2016-11-15 21 views
1

是否可以使用CLI將帶有Gradle插件(或任務)的jar添加到構建類路徑而不修改build.gradle?添加JAR是否可以從Maven存儲庫中解析?通過命令行添加動態依賴關係

buildscript { dependencies { classpath }}可以從CLI控制嗎?我可以使用CLI使Gradle從Maven解析JAR嗎?

基本上我需要達到同樣的情況與Maven,它可以根據

mvn <plugin-group-id>:<plugin-artifact-id>:<plugin-version>:<plugin-goal> 

我正在寫一對Maven and Gradle plugins提取有關項目和信息及其依賴成JSON文件,調用任何插件,可以稍後以編程方式處理。這個想法是能夠將其應用於大量的OSS項目,因此不需要修改它們。

+1

「是否有可能使用CLI應用與Maven的搖籃插件一個JAR存儲庫「這個聲明需要澄清。你想添加一個jar任務到構建?你想添加一個jar到編譯/運行時依賴關係嗎?目前還不清楚你想要什麼 –

+0

我更新了語句 – Viktor

+0

「build classpath」仍然含糊不清,因爲它可能意味着'buildscript {classpath ...}}或'dependencies {compile ...}}'或其他東西?運行時等 –

回答

3

我想我得到它現在

myinit-script.gradle

if (hasProperty('extraDependencies')) { 
    def extraDeps = property('extraDependencies').split(',') 
    allprojects { 
     buildscript { 
      dependencies { 
       classpath extraDeps 
      } 
     } 
    } 
} 

命令行

gradlew --init-script myinit-script.gradle -PextraDependencies=org.foo:bar:1.0,org.foo:baz:1.2 build 
+0

似乎我的問題確實很混亂,不好意思;( 我需要在構建腳本類路徑上創建自定義插件(或直線任務)並調用它。將'apply plugin'語句和'buildscript {dependencies {classpath}}'添加到'build.gradle' – Viktor

+0

已經通過[init-script]更新了答案(https://docs.gradle.org/current/userguide/ init_scripts.html#秒:using_an_init_script) –