Kevin Loveland
10/04/2024, 7:09 PMval externalImplementation by configurations.creating {
extendsFrom(configurations["implementation"])
}
val internalImplementation by configurations.creating {
extendsFrom(configurations["implementation"])
}
val external by sourceSets.creating {
kotlin.srcDir(sourceSets["main"].kotlin.srcDirs)
}
dependencies {
implementation(project("<some internal module>"))
internalImplementation("org.springframework.boot:spring-boot-starter-webflux:3.3.4")
externalImplementation(""org.springframework.boot:spring-boot-starter-webflux:3.1.4")
}
java {
registerFeature("external") {
usingSourceSet(external)
capability("$group", project.name, "$version")
}
}
tasks {
named("jar") {
dependsOn("externalJar")
}
}
This works for the "external" variant, but I cannot consume the internalImplementation configuration for the regular build. I know there is a simple way to get the necessary tasks to consume the new configuration without infecting the dependencies in the new variant. Still, I'm having trouble finding the syntax.Vampire
10/04/2024, 9:51 PMmain source set, not quite like you did it but similar.
Unfortunately, this is deprecated.
See here: https://github.com/gradle/gradle/issues/29455
It also contains a cumbersome way to work-around the deprecation.Kevin Loveland
10/04/2024, 10:31 PMimplemenation as a common ancestor.
In your example, there is a feature, java9, which is able to declare its own dependency, but in my case above, I require require two mutually exclusive dependencies required by the artifacts. Your example shows how one might change targetCompatiblity , which would be presumably overridden by the variant. In my case, one dependency does not override the other (except by way of dependency resolution).
I my case, I tried to use the main source set for one artifact and the variant for the other, but it would still require me to keep the spring-boot dependencies for the two variants separated. I almost got that working, but I could not figure out how to attach the additional configuration to the javaCompile task. I would also appreciate any guidance as to how I might be completely bastardizing the use of variants.Vampire
10/04/2024, 10:41 PMcompileJava? That sounds like a very bad idea.Kevin Loveland
10/04/2024, 10:46 PMcompileJava, it is really related to the dependencies required for generating the two artifacts. Both artifacts would require mutually exclusive dependencies which I had declared under different configurations. It would seem like I could ignore the main artifact and create two separate variant artifacts OR use the main artifact for one and the variant artifact for the other. In the case where I used the main artifact, I would need to attach one of the new configurations to be used for the compile task.
I’m probably doing things incorrectly here, but I’m kind of feeling around in the dark given the documentation available. 🙂Kevin Loveland
10/04/2024, 10:49 PMsrc/main uses any dependencies from spring-boot I will get a build failure because it cannot find the dependency since it simply uses the implemenation configuration and not the internalImplementation dependency.Kevin Loveland
10/04/2024, 10:50 PMexternalCompileJava will work fine.Kevin Loveland
10/04/2024, 10:56 PMVampire
10/04/2024, 11:13 PMdependsOn is evil too of course. Practically any explicit dependsOn where not a lifecycle task is on the left-hand side is a code smell and sign that you're doing something wrong.Kevin Loveland
10/04/2024, 11:28 PMresolutionStrategy block they must place in their root build file. This resolves their immediate problem.
2. Create divergent local dependencies within our set of projects (i.e., consume spring-boot:3.3.4 where it matters and spring-boot:3.1.4 where it doesn’t), but this seems wrong (we use a shared version catalog for our set of projects).
3. Generate two different variants/artifacts for the library which have two different sets of dependencies. I’d like to run tests against each set of dependencies independently. This is the reason for the question.Vampire
10/05/2024, 3:30 AMspring-boot:3.3.4 and a consumer says it needs at least spring-boot:3.1.4, of course 3.3.4 wins, so it kind of is a problem with your library. 😄
If your library does not need 3.3.4 but is also compatible with 3.1.4, why does it not say so?
You could maybe also instead use rich version and use 3.3.4 as prefer version instead of require, then the 3.1.4 of the consumer might simply win in conflict resolution if that really is what you want.