Hi,
I have a large legacy project written in several languages including Java. This project is assembled by the make utility for several targets and platforms. The last important thing is that the project may be assembled out of the project root folder.
When I decided to rewrite the assembling and distribution of the Java part of the project on Gradle, I faced the following problem. The make utility runs Gradle several times, ones for every combination of platform and target. The several Gradle runs is not a problem by itself. But coping of the build artifacts occurs every time when the dist folder is changed regardless of the presence of artifacts in the dist folder.
The simple example is below:
// gradle-test/build.gradle
plugins {
id 'java'
}
ext {
distRoot = file(getPropertyValueOrDefault('distDir', "${rootProject.projectDir}/build/dist"))
}
public <T> T getPropertyValueOrDefault(String propertyName, T defaultValue) {
T value = rootProject.findProperty(propertyName) as T
if (value == null) {
value = defaultValue
}
return value
}
sourceSets {
main.java.srcDirs = ['src']
}
tasks.register('dist', Copy) {
from jar
into distDir
// gradle-test/src/Dummy.java
public class Dummy {}
-
gradle dist -PdistDir=./dist1 -i
Three tasks are executed (classes, jar and dist) -
gradle dist -PdistDir=./dist2 -i
One task is executed (dist). The build directory is the same, the dist directory has been changed. -
gradle dist -PdistDir=./dist1 -i
Dist task is executed again. The build directory is the same, the dist directory has been changed. Butgradle-test.jar
already existed indist1
directory before running Gradle.
I know that this behavior is default for Gradle. But is there any way to exclude the value of distDir
property from Gradle cache?
I believe similar questions have already been asked, but I couldn’t find relevant discussions. I would appreciate any solutions.