我想执行一个自定义任务,它应该构建一些jar并将它们复制到另一个目录。
这是我的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
。
答案 0 :(得分:2)
from
)后, into
和<<
无法正常工作。它应该是:
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的工作原理至关重要。