условные зависимости в gradle - PullRequest
0 голосов
/ 03 июля 2018

Я работаю над сборкой нескольких проектов, используя gradle. У меня есть требование выбора зависимости от состояния свойства, введенного в командной строке.

Сценарий-1:

        dependencies {

            if( ! project.hasProperty("withsources")){


             compile 'com.xx.yy:x-u:1.0.2'

            }else{
              println " with sources"
              compile project (':x-u')
            }

        }

1.Когда я выполняю Gradle Run -Pwssources

    it is printing "withsources" 

2. Но для пробежки по грейдеру

    it is printing "withsources" 

Сценарий-2:

        dependencies {

            if(  project.hasProperty("withsources")){


             compile 'com.xx.yy:x-u:1.0.2'

            }else{
              println " with sources"
              compile project (':x-u')
            }

        }

1.Когда я выполняю Gradle Run -Pwssources

    it is not printing "withsources" 

2. Но для пробежки по грейдеру

    it is not printing "withsources" 

Я не знаю, это всегда идет в другой цикл. Любой может помочь здесь.

1 Ответ

0 голосов
/ 03 июля 2018

Я не могу сказать, в чем ваша проблема, не видя полного build.gradle, но ваш общий подход верен.

Вот небольшой пример, который работает для меня:

plugins {
    id "java"
}

repositories {
    jcenter()
}

dependencies {
    if (project.hasProperty("gson")) {
        implementation "com.google.gson:gson:2.8.5"
    } else {
        implementation "org.fasterxml.jackson.core:jackson-core:2.9.0"
    }
}

Нет объекта:

$ gradle dependencies --configuration implementation
:dependencies

------------------------------------------------------------
Root project
------------------------------------------------------------

implementation - Implementation only dependencies for source set 'main'. (n)
\--- org.fasterxml.jackson.core:jackson-core:2.9.0 (n)

(n) - Not resolved (configuration is not meant to be resolved)

BUILD SUCCESSFUL in 0s
1 actionable task: 1 executed

В собственности:

$ gradle -Pgson dependencies --configuration implementation
:dependencies

------------------------------------------------------------
Root project
------------------------------------------------------------

implementation - Implementation only dependencies for source set 'main'. (n)
\--- com.google.gson:gson:2.8.5 (n)

(n) - Not resolved (configuration is not meant to be resolved)

BUILD SUCCESSFUL in 0s
1 actionable task: 1 executed

Возможно ли, что вы определили с источниками где-то еще? Как в gradle.properties ?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...