Unable to overwrite property in Gradle in Multi-Project build

I installed the multi-module Gradle construct with several modules inside. What I'm trying to do is very simple - when I create a distribution, I would always like to use a directory called "dist / lib", except for one project for which it should just be "dist".

The obvious solution is to make a variable called "distLibDir" and overwrite it for the specific project in question does not work.

Here is the code for the submodule:

project.version = '1.1'

project.ext.distLibDir = 'dist'

dependencies {
....
}

And here is the code for the top-level project:

subprojects {
    apply plugin: 'java'
    apply plugin: 'eclipse'

    if (! project.hasProperty('distLibDir')) {
        project.ext.distLibDir = 'dist/lib'
    }

    task copyLib(type: Copy) {
        into project.distLibDir
        from configurations.runtime
    }

    task dist(type: Copy, dependsOn: [clean, jar, copyLib]) {
        from 'build/libs'
        into project.distLibDir
    }
}

No matter what I try, the directory is always displayed as "dist / lib" and I cannot overwrite it so that it differs from only one module. Does anyone know what's wrong here?

+4
1

. , , .

. - script suprojects (, if (project.path == ":foo") {...} else {...}). - subprojects (, , , ) script, script (, apply from: "$rootDir/gradle/foo.gradle"). script. ( ) , , , evaluationDependsOnChildren() script.

+4

Source: https://habr.com/ru/post/1529893/


All Articles