How do you change the default artifact in a multi-project build such that dependent projects get it instead of the original default artifact?
I have a Java project that produces a jar and, if the obfuscation task runs, an obfuscated jar.
If obfuscation happens I want the obfuscated jar to be the main/default artifact.
I have already managed to remove the unobfuscated jar from the archive artifacts and replace it with the obfuscated one. This results in the correct, obfuscated,jar being uploaded to our Artifactory server. The problem is that the jar passed on to downstream projects in a multi-project build remains the original unobfuscated jar.
I also tried adding the obfuscated jar to a new configuration and have the downstream projects depend on that specific configuration. That resulted in no jar being passed at all.
To replace the published artifact I do this:
configurations.archives.artifacts.clear();
artifacts {
archives file: file("$projectDir/build/proguard/${jar.archiveName}"), builtBy: obfuscate
archives file: file("$projectDir/build/proguard/proguard_map.txt"), name: “${project.name}”, classifier: ‘proguard_map’, builtBy: obfuscate
archives file: file("$projectDir/build/proguard/proguard_seeds.txt"), name: “${project.name}”, classifier: ‘proguard_seeds’, builtBy: obfuscate
javadocs javadocJar
archives javadocJar
}
Downstream projects do this to declare the dependency:
dependencies {
myFancyConfig project(path: ‘:MyProject’)
}
but I get the original jar artifact. I tried putting the obfuscated jar in a specific configuration, but it didn’t seem to work:
artifacts {
obfuscatedJar file("$projectDir/build/proguard/${jar.archiveName}"), builtBy: obfuscate
}
then the other project would use:
dependencies {
myFancyConfig project(path: ‘:MyProject’, configuration: ‘obfuscatedJar’)
}
but the jar was not present in myFancyConfig when I did this.
Perhaps I am making a simple mistake. Help please.