Steve Ebersole
05/31/2024, 2:51 PMA problem was found with the configuration of task ':sourcesJar' (type 'Jar').
- Gradle detected a problem with the following location: '/tmp/junit16008784648879827421/build/generated/sources/xjc/main/simple'.
Reason: Task ':sourcesJar' uses this output of task ':xjcSimple' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.
Possible solutions:
1. Declare task ':xjcSimple' as an input of ':sourcesJar'.
2. Declare an explicit dependency on ':xjcSimple' from ':sourcesJar' using Task#dependsOn.
3. Declare an explicit dependency on ':xjcSimple' from ':sourcesJar' using Task#mustRunAfter.
Please refer to <https://docs.gradle.org/8.0/userguide/validation_problems.html#implicit_dependency> for more details about this problem.
I add this generation task (itself) as a path in the main source-set's java sources:
final SourceSetContainer sourceSets = project.getExtensions().getByType( SourceSetContainer.class );
final SourceSet mainSourceSet = sourceSets.getByName( MAIN_SOURCE_SET_NAME );
mainSourceSet.getJava().srcDir( task );
What's super strange is that executing gradlew sourcesJar works perfectly fine. I only see this error when calling gradlew publishToMavneLocal (have not tried remote publishing yet)Steve Ebersole
05/31/2024, 2:52 PMVampire
05/31/2024, 2:58 PMwithSourcesJar()?Steve Ebersole
05/31/2024, 2:58 PMwithSourcesJar() . Sorry, should have mentioned thatVampire
05/31/2024, 2:59 PMSteve Ebersole
05/31/2024, 3:00 PMjava {
withJavadocJar()
withSourcesJar()
}
publishing {
publications {
// main publication
publishedArtifacts {
from components.java
}
...
}
...
}Vampire
05/31/2024, 3:00 PMSteve Ebersole
05/31/2024, 3:01 PMSteve Ebersole
05/31/2024, 3:01 PMSteve Ebersole
05/31/2024, 3:02 PMSteve Ebersole
05/31/2024, 3:03 PMSteve Ebersole
05/31/2024, 3:05 PMSteve Ebersole
05/31/2024, 3:06 PMSteve Ebersole
05/31/2024, 3:08 PMSteve Ebersole
05/31/2024, 3:10 PM#convention() to #set() there made no difference howeverVampire
05/31/2024, 3:32 PMsrcDir call in the configuration action of xjcTask. So this configuration is only done if the task is actually configured and only when it is configured.
You should probably move this outside the configuration lambda, so mainSourceSet.getJava().srcDir(xjcTaskRef) after the register call.Steve Ebersole
05/31/2024, 3:32 PMSteve Ebersole
05/31/2024, 3:32 PMSteve Ebersole
05/31/2024, 3:33 PMVampire
05/31/2024, 3:33 PMSteve Ebersole
05/31/2024, 3:34 PMSteve Ebersole
05/31/2024, 3:34 PMSteve Ebersole
05/31/2024, 3:36 PMpublishToMavenLocal none of the other tasks are triggeredSteve Ebersole
05/31/2024, 3:36 PMSteve Ebersole
05/31/2024, 3:41 PMVampire
05/31/2024, 3:43 PMdoes TestKit trigger task dependenciesSure, it is like calling Gradle from commandline or through IDE. It is just another tooling API using client. So if the depending tasks are not triggered, it seems something is not right
Steve Ebersole
05/31/2024, 3:44 PMSteve Ebersole
05/31/2024, 3:45 PMgradlew publishToMavenLocal in that test nothing is executed and I just get UP_TO_DATESteve Ebersole
05/31/2024, 3:47 PMSteve Ebersole
05/31/2024, 3:48 PMgradlew sourcesJar the jar is generated fine, including the generated sourcesSteve Ebersole
05/31/2024, 3:49 PMSteve Ebersole
05/31/2024, 3:49 PMSteve Ebersole
05/31/2024, 3:54 PM#set() instead of #convention() helpedSteve Ebersole
05/31/2024, 3:55 PMVampire
05/31/2024, 4:04 PMI should be using sourceSets.main.java and not sourceSets.main.allJava right?yes
Never quite understood the diffLet me quote the docs: `allJava`All Java source files for this source set. This includes, for example, source which is directly compiled, and source which is indirectly compiled through joint compilation. `java`The Java source which is to be compiled by the Java compiler into the class output directory.
java is more for configuring the Java source directory set.
allJava is for getting all Java sources, for example also those compiled by the Groovy joint compilation from the Groovy source directory set.Vampire
05/31/2024, 4:04 PMSpecifying a custom maven-local dir is not working via TestKitMaybe it needs to be done slightly different. 🤷♂️
Vampire
05/31/2024, 4:04 PMwithDebug as that runs the test in-process instead of starting a new processSteve Ebersole
05/31/2024, 4:05 PM.withEnvironment( Collections.singletonMap( "maven.repo.local", "\"" + mavenLocalPath.getAbsolutePath() + "\"" ) )Vampire
05/31/2024, 4:05 PMVampire
05/31/2024, 4:05 PMwithEnvironment sets an environment variable, I don't think that is correct here?Steve Ebersole
05/31/2024, 4:06 PM@TempDirSteve Ebersole
05/31/2024, 4:06 PMSteve Ebersole
05/31/2024, 4:06 PMfinal String mavenLocalPathProp = "-Dmaven.repo.local=\"" + mavenLocalPath.getAbsolutePath() + "\"";
.withArguments( "publishToMavenLocal", mavenLocalPathProp, ... )Steve Ebersole
05/31/2024, 4:07 PMSteve Ebersole
05/31/2024, 4:07 PMVampire
05/31/2024, 4:08 PMSteve Ebersole
05/31/2024, 4:08 PMVampire
05/31/2024, 4:08 PMmavenLocal but just a manually declared directory-based local repositorySteve Ebersole
05/31/2024, 4:09 PMVampire
05/31/2024, 4:09 PMSteve Ebersole
05/31/2024, 4:09 PMSteve Ebersole
05/31/2024, 4:28 PM