Unfortunately only a very narrow range of profile activations is supported still.
If this blog entry is still valid: Gradle's Support for Maven POM Profiles
then only profiles that are activated by default and profiles that are activated by absence of a system property.
I requested support for jdk
activated profiles here: https://github.com/gradle/gradle/issues/19224
you might want to thumbs-up it to show that you also like to have it.
How I currently deal with it is this in the settings script:
dependencyResolutionManagement {
components {
// work-around for https://github.com/gradle/gradle/issues/19224
withModule("org.apache.santuario:xmlsec") {
check(id.version == "2.2.1") {
"Please configure Java 9+ dependencies for $id"
}
listOf(
"java9Compile" to "compile",
"java9Runtime" to "runtime"
).forEach { (variant, base) ->
addVariant(variant, base) {
attributes {
attribute(TARGET_JVM_VERSION_ATTRIBUTE, 9)
}
withDependencies {
add("jakarta.xml.bind:jakarta.xml.bind-api:2.3.2")
}
}
}
}
}
}
which works by adding new variants for Java 9+ that have the additional dependencies and the consuming configuration have the target jvm version attribute automatically (should also work with 6.0.1 I think) and thus pick the correct configuration. If the project is completely Java 9+ you can of course simplify it and just add the dependencies to the existing variants like:
dependencyResolutionManagement {
components {
// work-around for https://github.com/gradle/gradle/issues/19224
withModule("org.apache.santuario:xmlsec") {
check(id.version == "2.2.1") {
"Please configure Java 9+ dependencies for $id"
}
listOf("compile", "runtime").forEach { variant ->
withVariant(variant) {
withDependencies {
add("jakarta.xml.bind:jakarta.xml.bind-api:2.3.2")
}
}
}
}
}
}
Remember to add runtime dependencies only to “runtime” and compile dependencies to both, “compile” and “runtime”.
For something like CXF it could for example look something like
dependencyResolutionManagement {
components {
// work-around for https://github.com/gradle/gradle/issues/19224
listOf(
"org.apache.cxf:cxf-core" to "3.4.2",
"org.apache.cxf:cxf-rt-bindings-soap" to "3.4.2",
"org.apache.cxf:cxf-rt-bindings-xml" to "3.4.2",
"org.apache.cxf:cxf-rt-databinding-jaxb" to "3.4.2",
"org.apache.cxf:cxf-rt-frontend-jaxws" to "3.4.2",
"org.apache.cxf:cxf-rt-frontend-simple" to "3.4.2",
"org.apache.cxf:cxf-rt-transports-http" to "3.4.2",
"org.apache.cxf:cxf-rt-ws-addr" to "3.4.2",
"org.apache.cxf:cxf-rt-ws-policy" to "3.4.2",
"org.apache.cxf:cxf-rt-wsdl" to "3.4.2"
).forEach { (module, version) ->
withModule(module) {
check(id.version == version) {
"Please configure Java 9+ dependencies for $id"
}
listOf("compile", "runtime").forEach { variant ->
withVariant(variant) {
withDependencies {
add("jakarta.annotation:jakarta.annotation-api:1.3.5")
add("jakarta.xml.ws:jakarta.xml.ws-api:2.3.3")
add("jakarta.jws:jakarta.jws-api:2.1.0")
add("jakarta.xml.soap:jakarta.xml.soap-api:1.4.2")
add("com.sun.activation:jakarta.activation:1.2.2")
add("org.jboss.spec.javax.rmi:jboss-rmi-api_1.0_spec:1.0.6.Final")
add("org.apache.geronimo.specs:geronimo-jta_1.1_spec:1.1.1")
}
}
}
withVariant("runtime") {
withDependencies {
add("com.sun.xml.messaging.saaj:saaj-impl:1.5.2")
}
}
}
}
}
}
Or actually as the dependencies are defined in the parent, assuming all in that group extend from it:
dependencyResolutionManagement {
components {
// work-around for https://github.com/gradle/gradle/issues/19224
all {
if (id.group != "org.apache.cxf") {
return@all
}
check(id.version == "3.4.2") {
"Please configure Java 9+ dependencies for $id"
}
listOf("compile", "runtime").forEach { variant ->
withVariant(variant) {
withDependencies {
add("jakarta.annotation:jakarta.annotation-api:1.3.5")
add("jakarta.xml.ws:jakarta.xml.ws-api:2.3.3")
add("jakarta.jws:jakarta.jws-api:2.1.0")
add("jakarta.xml.soap:jakarta.xml.soap-api:1.4.2")
add("com.sun.activation:jakarta.activation:1.2.2")
add("org.jboss.spec.javax.rmi:jboss-rmi-api_1.0_spec:1.0.6.Final")
add("org.apache.geronimo.specs:geronimo-jta_1.1_spec:1.1.1")
}
}
}
withVariant("runtime") {
withDependencies {
add("com.sun.xml.messaging.saaj:saaj-impl:1.5.2")
}
}
}
}
}
All shown variations complain if a different version is resolved so that you can review the added dependencies. If you add a new dependency that has jdk
enabled dependencies this will not be observed of course.