Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Be able to specify path for Generated code #2019

Closed
neelofer opened this issue Feb 27, 2020 · 9 comments
Closed

Be able to specify path for Generated code #2019

neelofer opened this issue Feb 27, 2020 · 9 comments

Comments

@neelofer
Copy link

neelofer commented Feb 27, 2020

Is your feature request related to a problem? Please describe.
I would like a way to provide the path for generated code for a service.

Describe the solution you'd like
Right now the code is generated in {project_dir/build/generated/source/apollo/main/{service name}/{rootPackagePath} path. It would nice to specify a path separately, related to the project dir. E.g. something like {project_dir}/src/main/generated/.... This is to be able to merge generated code in Git, similar to Swagger type behavior.

What I am using:
gradle 6.2.1
'com.apollographql.apollo' version '1.3.2'
Java 8

My build.gradle task:

apollo {
    onCompilationUnit {
        outputDir.set(file("src/main/generated")) //trying to set this did not help me
    }
    generateKotlinModels.set(false)
    service("sample") {
        sourceFolder.set("com/sample/servicename/path")
        rootPackageName.set("com.sample.servicename.path")
    }
}
@martinbonnin
Copy link
Contributor

martinbonnin commented Mar 1, 2020

Actually, i'd prefer swagger to generate files outside src/main/kotlin, see Yelp/swagger-gradle-codegen#102 (comment)

The generated code shouldn't be checked in source control because it duplicates information with the .graphql files.

Can you detail a bit more what your use cases would be ? Maybe there's a way to do it without adding files in the main source set ?

@martinbonnin
Copy link
Contributor

Closing due to inactivity, please reopen if needed.

@tobiasdiez
Copy link

We have the same issue. Other uses cases are IDE integration (auto completion) which sometimes doesn't work / needs special configuration, and usage with the Java module system. You also don't necessarily have to have the code under version control, simply add src/main/generated (or whatever path you choose) to gitignore.

So I hope this issue could be reopened. Thanks!

@martinbonnin

This comment has been minimized.

@martinbonnin martinbonnin reopened this Jun 6, 2021
@martinbonnin
Copy link
Contributor

martinbonnin commented Jun 6, 2021

Hi @tobiasdiez !

IDE integration (auto completion) which sometimes doesn't work / needs special configuration

If autocomplete doesn't work, it's definitely a bug that should be addressed either in Apollo Android or IntelliJ/Android Studio. Would you have a small reproducer we could dig into?

usage with the Java module system

Can you elaborate a bit more what is specific to the Java module system? I was under the impression that the generated files would be part of the module where the apollo plugin is applied but maybe I'm missing something.

Overall I'm not opposed to making the outputDir configurable but it seems that would hide other issues that we could fix in another better way.

@tobiasdiez
Copy link

tobiasdiez commented Jun 6, 2021

Thanks for your quick response.

If autocomplete doesn't work, it's definitely a bug that should be addressed either in Apollo Android or IntelliJ/Android Studio.

I had this problem using VS Code (which admittedly doesn't have the best Java integration). Everything in src/main is included by default, other things need special configuration.

Can you elaborate a bit more what is specific to the Java module system?

We are still experimenting with the module system integration (see #3152), but the short version is that one needs to specify the path of the module(s), see https://docs.oracle.com/javase/9/tools/jlink.htm. Thus the build/generated folder needs to be specified, and at the same time one needs to ensure that it is not treated as a new module.

In summary, nothing that (probably) cannot be fixed by some configuration of the external tools. It would be just easier if one could instruct the apollo plugin to generate the code in the same folder as other generated code so that this configuration has to be done only once. By the way, here is a good overview of the different conventions where to put generated code: https://stackoverflow.com/questions/22912900/location-of-generated-source-files-for-maven-directory-structure/64612308#64612308 (the build folder is not mentioned).

@martinbonnin
Copy link
Contributor

martinbonnin commented Jun 6, 2021

Thanks for all the context!

VSCode makes sense. I don't think they have any kind of Gradle integration so little can they know about the generated folder.

I don't think we want to move away from build/generated/sources/apollo as a default. It has been serving us well so far and the same kind of layouts are used by many other libs (sqldelight, wire, android gradle plugin, ...), not to mention that it makes it easy to delete the state of a (gradle) module easily (delete all build directory).

But we could make it configurable I think. It's used here. Maybe it's simply a matter of exposing the property to the extension.

@Siedlerchr
Copy link

This is also a problem with Eclipse:
Cannot nest 'jabref/build/generated/source' inside output folder 'jabref/build'
I tried to set the outputDir in the apollo Config but that did not work:

apollo {

  onCompilationUnit {
      outputDir.set(file("src-gen/main/java/")) // TODO not working yet
    // Overwrite some options here for single CompilationUnit if needed
  }
} 

@martinbonnin
Copy link
Contributor

Starting with 3.0.0-alpha01, you can set outputDir in your Gradle files:

apollo {
  outputDir.set("src-gen/main/java/")
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants