2013-06-04 183 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

相关问题