[GRADLE-1982] Should disabling a task automatically remove any artifact it might publish? Created: 06/Dec/11  Updated: 10/Feb/17  Resolved: 10/Feb/17

Status: Resolved
Project: Gradle
Affects Version/s: None
Fix Version/s: None

Type: Bug
Reporter: Gradle Forums Assignee: Unassigned
Resolution: Won't Fix Votes: 1

Attachments: Text File 0001-Added-conditional-omission-of-Ivy-artifacts-in-ivy-p.patch    


Is there a way to disable a task thereby also removing any artifact it might publish? For example, if anyone applies the `java` plugin but does not want sources being published, he/she should disable the `jarSource` task, but also search for its published artifact and remove it as well. In a more general case, I guess this might be handled with the following piece of code:


{ if (...) it.enabled = false }

afterEvaluate {

configurations.all {

artifacts.removeAll artifacts.findAll

{ it instanceof ArchivePublishArtifact && !it.archiveTask.enabled }



Are there better ways to accomplish this? If not, are there any chances for Gradle providing similar fuctionality, so that users would just need to disable/remove a task and its artifacts would be removed automatically?


Comment by Gradle Forums [ 06/Dec/11 ]

It doesn't, and doesn't even attempt to. [This issue]([1]http://forums.gradle.org/gradle/topic...) is related.

I've turned this into a problem and raised it as something to be solved.
[1] http://forums.gradle.org/gradle/topics/how_to_prevent_creation_of_jar_tasks_default_artifact

Comment by Mark Maxey [ 16/Apr/12 ]

I had a similar, but not identical issue. In my case, the output of tasks were used as inputs for associating artifacts with configurations. My problem was that the tasks were not executed because they didn't have any input files. While the artifacts of that task would never be created, the configuration was still linked to the artifact. This caused me problems when resolving dependencies of that configuration because the artifact wouldn't exist and the consumer of the resolved artifacts didn't know whether that was a good or bad thing.

My solution was to conditionally add artifacts to configurations. If the source set (or whatever task inputs) didn't exist for the task, then not only would I skip the task, I would not add any of that task's artifacts to my various configurations. I couldn't get there 100%, though, because the Java class JAR is added to various configurations (by the Java plugin I'm guessing).

Comment by Tim Enderling [ 16/Jul/13 ]

Added a patch that allows to specify an "onlyIf" closure/spec on an IvyArtifact, which will be evaluated just before the module descriptor is generated and the files to publish are determined. If the closure/spec return false, the artifact is omitted from both the descriptor and the upload. A minimal integration test is included.

Regarding GRADLE-1982 this is only the first step towards a solution (but the one that can hardly be solved by custom build configuration). This is also related to GRADLE-756.

Please consider adding this Contribution to your next release!

Comment by Benjamin Muschko [ 15/Nov/16 ]

As announced on the Gradle blog we are planning to completely migrate issues from JIRA to GitHub.

We intend to prioritize issues that are actionable and impactful while working more closely with the community. Many of our JIRA issues are inactionable or irrelevant. We would like to request your help to ensure we can appropriately prioritize JIRA issues you’ve contributed to.

Please confirm that you still advocate for your JIRA issue before December 10th, 2016 by:

  • Checking that your issues contain requisite context, impact, behaviors, and examples as described in our published guidelines.
  • Leave a comment on the JIRA issue or open a new GitHub issue confirming that the above is complete.

We look forward to collaborating with you more closely on GitHub. Thank you for your contribution to Gradle!

Comment by Benjamin Muschko [ 10/Feb/17 ]

Thanks again for reporting this issue. We haven't heard back from you after our inquiry from November 15th. We are closing this issue now. Please create an issue on GitHub if you still feel passionate about getting it resolved.

Generated at Wed Jun 30 12:09:36 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.