I have a project which is not a Java project in the traditional sense. It has no sources but produces “Java artifacts” (main, sources and javadoc jars). It does define dependencies through Configurations mainly to build the POM and for running some tests.
Initially I had defined this project using the java-library-plugin
. But because of the lack of source code, this caused many problems and I had to write a lot of code to remove / undo much of what the JavaPlugin contributes. Also, because there is no source, conceptually its not really a Java project.
So long story short, I dropped using the JavaPlugin and try to apply just the parts of the JavaPlugin I actually need. This worked great except that now I have problems resolving dependencies. E.g.
Could not determine the dependencies of task ':hibernate-core-jakarta:test'.
> Could not resolve all task dependencies for configuration ':hibernate-core-jakarta:testRuntimeClasspath'.
> Could not resolve org.junit.jupiter:junit-jupiter-params:5.7.1.
Required by:
project :hibernate-core-jakarta
project :hibernate-core-jakarta > org.junit.jupiter:junit-jupiter-api:5.7.1 > org.junit:junit-bom:5.7.1
> Cannot choose between the following variants of org.junit.jupiter:junit-jupiter-params:5.7.1:
- runtimeElements
- shadowRuntimeElements
All of them match the consumer attributes:
- Variant 'runtimeElements' capability org.junit.jupiter:junit-jupiter-params:5.7.1:
- Unmatched attributes:
- Provides org.gradle.category 'library' but the consumer didn't ask for it
- Provides org.gradle.dependency.bundling 'external' but the consumer didn't ask for it
- Provides org.gradle.jvm.version '8' but the consumer didn't ask for it
- Provides org.gradle.libraryelements 'jar' but the consumer didn't ask for it
- Provides org.gradle.status 'release' but the consumer didn't ask for it
- Provides org.gradle.usage 'java-runtime' but the consumer didn't ask for it
- Provides org.jetbrains.kotlin.localToProject 'public' but the consumer didn't ask for it
- Provides org.jetbrains.kotlin.platform.type 'jvm' but the consumer didn't ask for it
- Variant 'shadowRuntimeElements' capability org.junit.jupiter:junit-jupiter-params:5.7.1:
- Unmatched attributes:
- Provides org.gradle.category 'library' but the consumer didn't ask for it
- Provides org.gradle.dependency.bundling 'embedded' but the consumer didn't ask for it
- Provides org.gradle.jvm.version '8' but the consumer didn't ask for it
- Provides org.gradle.libraryelements 'jar' but the consumer didn't ask for it
- Provides org.gradle.status 'release' but the consumer didn't ask for it
- Provides org.gradle.usage 'java-runtime' but the consumer didn't ask for it
Part of dropping the JavaPlugin was that I needed to manually create the needed Configurations and wire them up. For the most part, that seems to work.
However, for external dependencies that publish Gradle metadata with multiple variants, my attempts to configure the Configurations fail as seen from above. It would seem pretty clear that the JavaPlugin applies some form of ResolutionStrategy tweaks to resolve these variants. I did dig into JavaPlugin, JavaBasePlugin, etc but was unable to figure out what tweaks I need exactly.
As far as I can tell, this variation in particular seems to be related to picking a normal jar versus picking a fat-jar.