Gradle 7.2 Explict dependencies

I have the below build.gradle file. The task assignVersion generates a file from a template that needs to be included in the distribution zip file created by distZip.

If I run this in gradle 7.2 I get warning that are show below. I am not at all understanding what is causing this and how to resolve this without adding a lot of dependsOn.

plugins {
  id 'java-library'
  id 'distribution'
}

version="1.0"

sourceSets {
  main {
    java.srcDirs = ['src']
  }
}

task assignVersion(type: Copy) {
  destinationDir = projectDir
  from projectDir 
  include "**/*.template"
  rename '(.+).template', '$1'
  filter { line ->
    line.replaceAll("test.version.number", "${version}")
  }
}

jar {
  archiveBaseName = "test"
  includeEmptyDirs = false
  manifest {
    attributes 'Implementation-Title': "Test",
               'Implementation-Version': archiveVersion
   }
}

distZip {
  into "test", {from projectDir include "myfile", "config/*.cfg"}
  into "test/code/jars", {from jar}
}

distZip.dependsOn(assignVersion)

Here is the output:

> Task :compileJava
Execution optimizations have been disabled for task ':compileJava' to ensure correctness due to the following reasons:
  - Gradle detected a problem with the following location: 'C:\Users\rupin\git\test\build\classes\java\main'. Reason: Task ':assignVersion' uses this output of task ':compileJava' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to https://docs.gradle.org/7.2/userguide/validation_problems.html#implicit_dependency for more details about this problem.
  - Gradle detected a problem with the following location: 'C:\Users\rupin\git\test\build\generated\sources\annotationProcessor\java\main'. Reason: Task ':assignVersion' uses this output of task ':compileJava' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to https://docs.gradle.org/7.2/userguide/validation_problems.html#implicit_dependency for more details about this problem.
  - Gradle detected a problem with the following location: 'C:\Users\rupin\git\test\build\generated\sources\headers\java\main'. Reason: Task ':assignVersion' uses this output of task ':compileJava' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to https://docs.gradle.org/7.2/userguide/validation_problems.html#implicit_dependency for more details about this problem.
  - Gradle detected a problem with the following location: 'C:\Users\rupin\git\test\src'. Reason: Task ':compileJava' uses this output of task ':assignVersion' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to https://docs.gradle.org/7.2/userguide/validation_problems.html#implicit_dependency for more details about this problem.

> Task :jar
Execution optimizations have been disabled for task ':jar' to ensure correctness due to the following reasons:
  - Gradle detected a problem with the following location: 'C:\Users\rupin\git\test\build\classes\java\main'. Reason: Task ':jar' uses this output of task ':assignVersion' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to https://docs.gradle.org/7.2/userguide/validation_problems.html#implicit_dependency for more details about this problem.
  - Gradle detected a problem with the following location: 'C:\Users\rupin\git\test\build\resources\main'. Reason: Task ':jar' uses this output of task ':assignVersion' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to https://docs.gradle.org/7.2/userguide/validation_problems.html#implicit_dependency for more details about this problem.
  - Gradle detected a problem with the following location: 'C:\Users\rupin\git\test\build\tmp\jar\MANIFEST.MF'. Reason: Task ':jar' uses this output of task ':assignVersion' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to https://docs.gradle.org/7.2/userguide/validation_problems.html#implicit_dependency for more details about this problem.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

Can you clarify what you actually have? When you say, “a file” and “a template”, do you mean that there is only one .template file in the project? The current assignVersion task is written like there’s many .template files scattered all over the project and then they all need to add a version number.

The task really needs to write somewhere other than in place, but depending on your answer this can be greatly simplified.

@jjustinic in this case actually there are two template files in the project root folder. But there can be others in future so that is why its written like that. The plan was to have a .template file in the same folder where the target file is needed and let the build substitute the version number. All that the task needs to do is to use the template, put the version number in those and create another file with the same name but without the .template extension. Hope that clarifies.

@jjustinic any update on my query on this ?

What else are you looking for?

The answer is still that you shouldn’t write the output in place because projectDir intersects everything else, just you can’t simplify it as much.