Nino
07/25/2024, 10:51 AMtask jarTest(type: Jar, dependsOn: 'compileDebugUnitTestSources') {
from 'build/tmp/kotlin-classes/debugUnitTest'
}
configurations {
testOutput
}
artifacts {
testOutput jarTest
}
and I got this code, but it seems weird to create a testOutput
val and never use it directly. Is there another way ?
val jarTest = tasks.register<Jar>("jarTest") {
dependsOn("compileDebugUnitTestSources")
from("build/tmp/kotlin-classes/debugUnitTest")
}
val testOutput: Configuration by configurations.creating
artifacts {
add("testOutput", jarTest)
}
CLOVIS
07/25/2024, 12:10 PMit seems weird to create aThere are other ways, but this is the recommended way, because it makes referring to things easier and less error-prone.val and never use it directly. Is there another way ?testOutput
CLOVIS
07/25/2024, 12:10 PM.registering
instead of .creating
, but specifically for Configuration, I don't think it makes a difference)CLOVIS
07/25/2024, 12:11 PMNino
07/25/2024, 12:13 PMtestImplementation(project(path = "foo", configuration = "testOutput"))
This is basically a "in-house" java-fixture thing I guessCLOVIS
07/25/2024, 12:15 PMjarTest
is part of the configuration? I'm not an expert on the APIs, but I don't like that it's implicitNino
07/25/2024, 12:16 PMCLOVIS
07/25/2024, 12:16 PMNino
07/25/2024, 12:17 PMCLOVIS
07/25/2024, 12:19 PMval testOutput: Configuration by configurations.creating
artifacts {
add(testOutput.name, jarTest)
}
just so it's clearer that they both go together
If you have the possibility, using variants would make the build more stable for the futureNino
07/25/2024, 12:21 PMVampire
07/25/2024, 1:20 PMit seems weird to create aThen do use it directly:val and never use it directlytestOutput
val testOutput: Configuration by configurations.creating
artifacts {
add("testOutput", jarTest)
}
||
v
val testOutput: Configuration by configurations.creating
artifacts {
add(testOutput.name, jarTest)
}
Or follow the same pattern you did for the task creation where you also did not use the by
property delegate:
val testOutput by configurations.creating
artifacts {
add("testOutput", jarTest)
}
||
v
configurations.create("testOutput")
artifacts {
add("testOutput", jarTest)
}
But then as CLOVIS said, the names could derive like in your orignal code, so imho better use the first variant.
What is your configuration for though, if you don't use it?He does use the configuration right 2 lines below declaring it, just not the variable that references it.
What I find strange here is that it somehow guesses thatIt is not, he defines that by using the configuration name, just hard-coded instead of using the variable.is part of the configuration? I'm not an expert on the APIs, but I don't like that it's implicitjarTest
btw, the official way to implement something like java-fixturesDepends on whether you want the variants to also be shared to outside projects or only withing the same build, and if the latter whether you need the full variant / attribute experience or whether explicitly asking for the configuration is sufficient. For simple cases the latter is just fine.
CLOVIS
07/25/2024, 1:37 PMHe does use the configuration right 2 lines below declaring it, just not the variable that references it. It is not, he defines that by using the configuration name, just hard-coded instead of using the variable.I went to read the docs, and indeed, the name of the artifact must match the name of the configuration. That was surprising to me, because usually the name is just used to refer to things and doesn't mean anything, but well.
CLOVIS
07/25/2024, 1:38 PMFor simple cases the latter is just fine.Good to know, thanks
Vampire
07/25/2024, 1:44 PMI went to read the docs, and indeed, the name of the artifact must match the name of the configuration. That was surprising to me, because usually the name is just used to refer to things and doesn't mean anything, but well.Why do you call it "name of the artifact"? It is not the name of the artifact. It is the name of the configuration to which the artifact should be added. Hence the parameter is also called
configurationName
🙂Vampire
07/25/2024, 1:44 PM