When applying Gradle's (8.5) application plugin, and setting property archiveClassifier a task dependency error is raised, which looks like is unnecessary.

The error is raised when:

  • Download a Spring initializr project:
  • Spring Boot 3.2.0,
  • Java 17,
  • Groovy build language.
  • Bump the Gradle version to 8.5.
  • Extend build.gradle:
  • Add Gradle plugin application,
  • Add Groovy script: groovy tasks.withType(AbstractArchiveTask).configureEach { archiveClassifier.set("fubar") }

Running ./gradlew clean build will raise the following error.

FAILURE: Build failed with an exception.

* What went wrong:
Some problems were found with the configuration of task ':jar' (type 'Jar').
  - Gradle detected a problem with the following location: '/home/meijer/Documents/wip/gradle-bug/build/libs/demo-0.0.1-SNAPSHOT-fubar.jar'.

    Reason: Task ':bootDistZip' uses this output of task ':jar' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.

    Possible solutions:
      1. Declare task ':jar' as an input of ':bootDistZip'.
      2. Declare an explicit dependency on ':jar' from ':bootDistZip' using Task#dependsOn.
      3. Declare an explicit dependency on ':jar' from ':bootDistZip' using Task#mustRunAfter.
...

A minimal example can also be found here: https://github.com/Meijuh/spring-boot-gradle-85-issue.

Note; this error is also triggered with Spring Boot 2.7.18.

Comment From: wilkinsona

Thanks for the report. This doesn't appear to be specific to Gradle 8.5. I see the same problem with 8.1.1:

* What went wrong:
Some problems were found with the configuration of task ':jar' (type 'Jar').
  - Gradle detected a problem with the following location: '/Users/awilkinson/dev/temp/spring-boot-gradle-85-issue/build/libs/demo-0.0.1-SNAPSHOT-fubar.jar'.

    Reason: Task ':bootDistZip' uses this output of task ':jar' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.

    Possible solutions:
      1. Declare task ':jar' as an input of ':bootDistZip'.
      2. Declare an explicit dependency on ':jar' from ':bootDistZip' using Task#dependsOn.
      3. Declare an explicit dependency on ':jar' from ':bootDistZip' using Task#mustRunAfter.

    Please refer to https://docs.gradle.org/8.1.1/userguide/validation_problems.html#implicit_dependency for more details about this problem.
  - Gradle detected a problem with the following location: '/Users/awilkinson/dev/temp/spring-boot-gradle-85-issue/build/libs/demo-0.0.1-SNAPSHOT-fubar.jar'.

    Reason: Task ':bootDistTar' uses this output of task ':jar' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.

    Possible solutions:
      1. Declare task ':jar' as an input of ':bootDistTar'.
      2. Declare an explicit dependency on ':jar' from ':bootDistTar' using Task#dependsOn.
      3. Declare an explicit dependency on ':jar' from ':bootDistTar' using Task#mustRunAfter.

    Please refer to https://docs.gradle.org/8.1.1/userguide/validation_problems.html#implicit_dependency for more details about this problem.
  - Gradle detected a problem with the following location: '/Users/awilkinson/dev/temp/spring-boot-gradle-85-issue/build/libs/demo-0.0.1-SNAPSHOT-fubar.jar'.

    Reason: Task ':bootStartScripts' uses this output of task ':jar' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.

    Possible solutions:
      1. Declare task ':jar' as an input of ':bootStartScripts'.
      2. Declare an explicit dependency on ':jar' from ':bootStartScripts' using Task#dependsOn.
      3. Declare an explicit dependency on ':jar' from ':bootStartScripts' using Task#mustRunAfter.

    Please refer to https://docs.gradle.org/8.1.1/userguide/validation_problems.html#implicit_dependency for more details about this problem.

Comment From: wilkinsona

Looking more closely, I think this is a configuration error. By configuring all AbstractArchiveTasks to use the fubar classifier, the jar and the bootJar tasks are now both going to output an archive to the same location. One will overwrite the other depending on the order in which they're executed. This also confuses Gradle as it now believes that the bootDistZip task will use the output of the jar task when, in fact, it should use the output of the bootJar task. If the jar and bootJar tasks are configured with different classifiers (as they are by default and as they should be), the problem does not occur.