2013-06-04 96 views
0

我創建了自定義任務,發佈在常青藤資源庫中,現在我想使用它。這就是我要做的事:使用自定義gradle任務

configurations { 
    customTask { 
     transitive = false 
    } 
} 

repositories { 
    mavenCentral() 
    ivy { 
     url 'http://my.ivy.rep/ivyrep/shared' 
     layout "pattern", { 
      artifact "[organisation]/[module]/[revision]/[type]s/[artifact].[ext]" 
     } 
    } 
} 

dependencies { 
    customTask 'org.apache.ant:ant-jsch:1.8.4' 
    customTask 'com.jcraft:jsch:0.1.49' 
    customTask group: 'pl.com', name:'MyCustomTask', version:'0.9', configuration: 'runtime' 
} 

task buildInstaller(type: eu.company.gradle.MyCustomTask) { 
    ... 
} 

這是我的自定義任務:

package eu.company.gradle 
class MyCustomTask extends DefaultTask { 

    public MyCustomTask() {} 

    @TaskAction 
    def build() { 
     // do something 
    } 
} 

依賴被下載,但是當我要運行「buildInstaller」的任務,我得到這個錯誤:

Could not find property 'pl' on root project 'Configurable installer'. 

看起來我的jar不在classpath中?

回答

0

Gradle User Guide「56.3.1在另一個項目中使用你的任務類」:

buildscript { 
    repositories { 
     maven { 
      url uri('../repo') 
     } 
    } 
    dependencies { 
     classpath group: 'org.gradle', name: 'customPlugin', version: '1.0-SNAPSHOT' 
    } 
} 

task greeting(type: org.gradle.GreetingTask) { 
    greeting = 'howdy!' 
} 

完整的搖籃分佈具有完整的示例代碼。

+0

好的,謝謝,但我的構建以這種方式工作,所以問題在哪裏? – pepuch

+1

它沒有。注意'buildscript'塊。 –

+0

Ohhhhh,謝謝! – pepuch

相關問題