Caleb Cushing
03/07/2025, 7:41 PM// Automatically generate GraphQL code on project build:
compileJava.dependsOn 'graphqlCodegen'
// Add generated sources to your project source sets:
sourceSets.main.java.srcDir "$buildDir/generated"
it does seem to compile (as evidence by having to add deps to make compile errors go away) but my subproject doesn't seem to make these classes available such that another subproject can consume them. Nor are the generated sources recognized as sources. please adviseTrevJonez
03/07/2025, 9:06 PMCaleb Cushing
03/07/2025, 9:10 PMTrevJonez
03/07/2025, 9:11 PMCaleb Cushing
03/07/2025, 9:12 PMTrevJonez
03/07/2025, 9:13 PMCaleb Cushing
03/07/2025, 9:25 PMsourceSets.main.java.srcDirs(tasks.graphqlCodegen)
works... but I've no idea if that's a good way to do this. Honestly the problem might not really be the plugin but its documentation. I'm speculating that their might not be an intent to have the code uncommitted... or, whatever, be more flexible because it shows how to do more than one task.TrevJonez
03/07/2025, 9:26 PMTrevJonez
03/07/2025, 9:27 PMCaleb Cushing
03/07/2025, 9:29 PMsourceSets.main.java.srcDir
although maybe it's more eager...TrevJonez
03/07/2025, 9:29 PMCaleb Cushing
03/07/2025, 9:29 PMTrevJonez
03/07/2025, 9:29 PMCaleb Cushing
03/07/2025, 9:30 PMCaleb Cushing
03/07/2025, 9:31 PMdependsOn
should (almost) never be needed and buildDir
is deprecated
// Automatically generate GraphQL code on project build:
compileJava.dependsOn 'graphqlCodegen'
// Add generated sources to your project source sets:
sourceSets.main.java.srcDir "$buildDir/generated"
Caleb Cushing
03/07/2025, 9:31 PMCaleb Cushing
03/07/2025, 9:36 PMTrevJonez
03/07/2025, 9:37 PMCaleb Cushing
03/07/2025, 9:39 PMPhilip W
03/08/2025, 10:54 AMPhilip W
03/08/2025, 10:56 AMThomas Broyer
03/08/2025, 11:27 AMsrcDir(files("$buildDir/generated") { builtBy("graphqlCodegen") })
(or possibly srcDirs
?)Caleb Cushing
03/08/2025, 12:35 PMCaleb Cushing
03/10/2025, 3:33 PMmain
works, but what if you want a modifiable main? the generated code should have a different sourceSet? does a feature make sense there? or some other pattern?
https://github.com/kobylynskyi/graphql-java-codegen/issues/1585Vampire
03/12/2025, 4:01 PMsrcDir(theTask)
or `srcDir(someThingElseWithTaskDependencyLikeSomethingWithBuiltBy)`is the correct way to go (well, maybe with layout.buildDirectory
instead of buildDir
.
And as you assumed, the docs of that plugin are just horribly wrong if they recommend to configure the path and the task dependency manually as it only works in corner cases.
If you properly wire the task as source directory, then any consumer of sources files also gets the generated source files and has the necessary task dependency so that they are generated if necessary.Vampire
03/12/2025, 4:03 PMsourceSets.main
gives you a SourceSet
while on Kotlin DSL sourceSets.main
gives you a NamedDomainObjectProvider<SourceSet>
.Caleb Cushing
03/12/2025, 4:04 PMVampire
03/12/2025, 4:24 PMmain
source set is the right one, yes.
Since then you would also have to add src /main /Java.Why should you need to add what is already the default? Unless you used
setSrcDirs
which overwrites all previously configured values.
If the source set isn't main I would have no idea how to "import" it into mainLike with any other source set, you would depend on it, but as I said, in most cases that is not what you want.
Philip W
03/12/2025, 5:00 PMVampire
03/12/2025, 5:28 PMCaleb Cushing
03/13/2025, 7:15 PMCaleb Cushing
03/13/2025, 7:16 PMPhilip W
03/13/2025, 7:39 PM