2015-11-02 45 views
0

我想执行一个自定义任务,它应该建立一些罐子并将它们复制到不同的目录。如何用gradle复制多重罐子?

这是我build.gradle文件:

allprojects { 
    apply plugin: 'java' 
    apply plugin: 'eclipse' 
    task hello << { task -> println "I'm project $task.project.name" } 
} 

subprojects { 
    repositories { 
    maven { 
     url "http://repo1.maven.org/maven2" 
    } 
    } 

    task allDependencies(type: DependencyReportTask) {} 
    task allDependenciesInsight(type: DependencyInsightReportTask) << {} 

    dependencies { 
    compile 'log4j:log4j:1.2.14' 
    compile 'org.eclipse.jdt:org.eclipse.jdt.annotation:2.0.+' 

    testCompile "junit:junit:4.+" 
    testCompile 'org.mockito:mockito-all:1.10.+' 
    } 

    task copyJars(type: Copy) << { 
    println "Copies artifacts from " + project.libsDir + " to " + project.rootDir + "." 
    from('$project.libsDir') 
    into('$project.rootDir') 
    } 
} 

task bamm(type: Copy) << { 
    description "Creates BAMM plugin." 
    println "Creates BAMM plugin." 
    println "Copies artifacts from " + project.libsDir + " to " + gradle.bammDir 
    from(project.libsDir) 
    into(gradle.bammDir) 
} 

bamm.dependsOn ':camm-server:jar', ':camm-server:copyJars' 

project(':camm-shared') { 
    dependencies { 
    compile 'joda-time:joda-time:1.5.2' 
    compile 'org.springframework:spring:2.5.6.+' 
    compile files ('../lib/MarketInterface.jar') 
    } 
} 

project(':camm-client') { 
    dependencies { 
    compile 'org.jfree:jfreechart:1.0.+' 
    compile project(':camm-shared') 
    } 
} 

project(':camm-server') { 
    dependencies { 
    compile 'org.jibx:jibx-run:1.2.+' 
    compile project(':camm-client') 
    compile project(':camm-shared') 

    testCompile files ('../lib/MarketInterface.jar') 
    testCompile project(':camm-shared').sourceSets.test.output 
    } 
} 

task wrapper(type: Wrapper) { 
    gradleVersion = '2.8' 
} 

我可以运行BAMM任务,但它决不会复制任何东西。

我的目标是建立所有必需的罐子(工作)并将从我的项目创建的所有罐子复制到gradle.bammDir

回答

2

frominto当在动作<<)中添加时不起作用。它应该是:

task bamm(type: Copy) { 
    description "Creates BAMM plugin." 
    println "Creates BAMM plugin." 
    println "Copies artifacts from " + project.libsDir + " to " + gradle.bammDir 
    from(project.libsDir) 
    into(gradle.bammDir) 
} 

或:

task bamm << { 
    description "Creates BAMM plugin." 
    println "Creates BAMM plugin." 
    println "Copies artifacts from " + project.libsDir + " to " + gradle.bammDir 
    copy { 
    from(project.libsDir) 
    into(gradle.bammDir) 
    } 
} 

请阅读有关配置执行阶段 - 它的关键是要了解如何gradle这个作品。