2

マルチプロジェクトのgradleビルドがあります。2 つのサブプロジェクトのみに配布タスクを設定したいと考えています。

ルート プロジェクトとサブ プロジェクト A、B & C があるとします。B & C のみの配布タスクを構成したいと考えています。

次の方法で動作します:
root_project/build.gradle

subprojects{

   configure ([project(':B'), project(":C")]) {

       apply plugin: 'java-library-distribution'
       distributions {
       main {
            contents {
                from('src/main/') {
                    include 'bin/*'
                    include 'conf/**'
                }
            }
        }
    }
}

しかし、私はそれをこのように機能させることに興味があります

subprojects{

   configure (subprojects.findAll {it.hasProperty('zipDistribution') && it.zipDistribution}) ) {

       apply plugin: 'java-library-distribution'
       distributions {
       main {
            contents {
                from('src/main/') {
                    include 'bin/*'
                    include 'conf/**'
                }
            }
        }
    }
}

B & C の build.gradle には、次のようになります。

ext.zipDistribution = true

後者のアプローチでは、次の2つの問題があります。

問題1

* What went wrong:
Task 'distZip' not found in root project 'root_project'.

* Try:
Run gradle tasks to get a list of available tasks.

問題 2

zipDistribution以下のコードでroot_projectにプロパティが読み込めるか検証してみました

subprojects {
    .....
//    configure ([project(':B'), project(":C")]) {

        apply plugin: 'java-library-distribution'
        distributions {
            /* Print if the property exists */

            println it.hasProperty('zipDistribution')
            main {
                contents {
                    from('src/main/') {
                        include 'bin/*'
                        include 'conf/**'
                    }
                }
            }
        }
//    }

      .....
}

上記は、it.hasProperty('zipDistribution') に対して null を出力します。

これらの問題が表示されないように、誰かが正しいアプローチを教えてもらえますか?

4

1 に答える 1

1

これは、ルート プロジェクトの後にサブプロジェクトが構成されるためです。これがその時点の理由ext.zipDistributionです(まだ設定されていません)。null

afterEvaluateそれを避けるために使用する必要があります:

subprojects {
    afterEvaluate { project ->
        if (project.hasProperty('zipDistribution') && project.zipDistribution) {
            ....
        }
    }
}
于 2014-10-31T19:12:50.313 に答える