2016-09-16 107 views
0

我有以下線在我的gradle這個插件代碼搖籃插件不詹金斯

def cmd = "./gradlew -q ":app:dependencies --configuration compile" 
def proc = cmd.execute() 
def output = proc.text.trim() 

正確地執行命令,當我在我的本地計算機上執行gradle這個命令

./gradlew clean build 

我可以看到正確的價值輸出變量。但是當我通過jenkins作業運行相同的命令時,變量輸出在其中沒有任何價值。

我無法弄清楚這裏發生了什麼。

我的本地機器是Mac和遠程詹金斯箱是在Linux

+0

不知道你要完成的任務。似乎充其量這會導致循環。你想添加一個任務到構建?什麼是實際目標? – JBirdVegas

+0

@JBirdVegas嗯,我試圖修復一個人寫的插件。目標是在發佈構建過程中獲取項目的所有依賴項的列表,並將其捕獲到註釋中。我想使用項目對象來獲得編譯時間構建依賴關係會更好。可能我會在未來增強代碼。現在我發現這個問題與一些命令行參數有關。由於代碼僅使用來自proc對象的Sysout流並忽略err流,因此未顯示錯誤原因。設置命令行參數後,問題現在已解決。 – prashant

+0

這個代碼與項目'app'是否在同一個版本中?在'所顯示的代碼的運行環境是什麼?在插件或其他的'build.gradle'中? – JBirdVegas

回答

1

您可以生成依賴關係圖不會再次調用gradlew

真的你想要的是一個插件,其任務是在dependencyReport之後運行並讀取創建的文件。這應該爲你做。

apply plugin: 'java' 

repositories { 
    jcenter() 
} 

dependencies { 
    compile group: 'com.google.code.gson', name: 'gson', version: '2.7' 
    compile group: 'commons-io', name: 'commons-io', version: '2.5' 
} 

apply plugin: DepReport 

class DepReport implements Plugin<Project> { 
    @Override 
    void apply(Project project) { 
     project.pluginManager.apply('project-report') 
     def reportTask = project.tasks.create('myReport', DepTask) { 
      group = 'reports' 
      description = "Create our report" 
     } 
     reportTask.dependsOn 'dependencyReport' 
     reportTask.outputs.upToDateWhen { false } 
    } 
} 

class DepTask extends DependencyInsightReportTask { 
    @OutputFile 
    def output = new File("$project.buildDir.absolutePath/reports/project", "dependencies.txt") 

    DepTask() { 
     configuration = project.configurations.getByName('compile') 

    } 

    @Override 
    @TaskAction 
    void report() { 
     def dependencies = output.text.trim() 
     println "Found dependencies to be $dependencies.chars.length chars long" 
     // you could print them or manipulate the text as desired but the text is large 
    } 
} 

輸出:

$ ./gradlew myReport 
Configuration on demand is an incubating feature. 
:app:dependencyReport 
:app:myReport 
Found dependencies to be 1301 chars long 

BUILD SUCCESSFUL 

Total time: 0.712 secs