Skip an artifact during build through configuration


(Appu Goundan) #1

I have a plugin helps generate client api config which clients can consume by referencing the configuration in the other project.

in client :

dependencies {
  customConfig project(path: "server", configuration: "clientConsumable")

where clientConsumable is a configuration in the plugin configured like this

Zip someZipTask = project.getTasks().create("_clientZipGenerator", Zip.class);
//... configure it here

project.getArtifacts().add("clientConsumable", someZipTask);

Now I have a server plugin that exposes this configuration and artifact. Perhaps I am doing this wrong, but I only want the server to generate the archive IF there is exists a client in the same project that has a dependency on the configuration. If no client exists, then _clientZipGenerator does NOT execute.

Is there a way to configure this artifact generation to be conditional on another module having an explicit dependency on the configuration?

What’s weird is that Jar tasks are skipped if not references, but Zip tasks are not.

(Appu Goundan) #2

Self bump with update (jar -> zip as in my actual code)

(Appu Goundan) #3

Digging deeper into the gradle source code is the super weird file : which determines priority of the artifacts being added to the default set for war, ear and jar and other. The default set is what determines what the “assemble” task creates as it has a dependency on DefaultPublishArtifactSet (and not the tasks to create them).

@mark_vieira, when we talked about this at the gradle summit, the solution we came up with was to remove the task from the assemble dependsOn, but it’s actually pulling it in directly from the artifact reference, which I cannot seem to change.

I’m starting to think there is no actual solution to this currently, and a nice feature would be for some archive tasks should be allowed to configure themselves to not be included in the DefaultPublishArtifactSet (perhaps through a new method PublishArtifact.isSkipOnDefault or something (naming?))

There is a secondary problem here : I think there’s an ordering problem too with where someone could create an archive before applying the java plugin and no jar will be created.

configurations {

task customZip {
  from "src"
  archiveName ""

artifacts.add "customConfig", tasks.customZip

apply plugin: "java"
$ ./gradlew assemble

Jar is ignored, which may or may not be the intended behavior?

(Mark Vieira) #4

I’m wonder if using the “new” publishing plugins would solve this for you, as you can then define individual publications instead of adding everything to the archives configuration.