gpt4 book ai didi

java - 如何用gradle复制多个jar?

转载 作者:行者123 更新时间:2023-12-02 04:14:16 29 4
gpt4 key购买 nike

我想执行一个自定义任务,该任务应该构建一些 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 任务,但它从不复制任何内容。

我的目标是构建所有必要的 jar(有效)并将从我的项目创建的所有 jar 复制到 gradle.bammDir

最佳答案

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 的工作原理至关重要。

关于java - 如何用gradle复制多个jar?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33482374/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com