gpt4 book ai didi

java - Gradle 清理并复制 JAR 文件

转载 作者:行者123 更新时间:2023-11-30 07:48:09 25 4
gpt4 key购买 nike

我正在使用 Gradle 构建一个 Java 应用程序,我想将最终的 jar 文件传输到另一个文件夹中。我想在每个 build 上复制文件并在每个 clean 上删除文件。

不幸的是,我只能完成其中一项任务,而不能同时完成两项任务。当我激活任务 copyJar 时,它成功地复制了 JAR。当我包含 clean 任务时,JAR 不会被复制,如果那里有文件,它会被删除。就好像有一些任务调用clean

有什么解决办法吗?

plugins {
id 'java'
id 'base'
id 'com.github.johnrengelman.shadow' version '2.0.2'
}
dependencies {
compile project(":core")
compile project("fs-api-reader")
compile project(":common")
}

task copyJar(type: Copy) {
copy {
from "build/libs/${rootProject.name}.jar"
into "myApp-app"
}
}

clean {
file("myApp-app/${rootProject.name}.jar").delete()
}

copyJar.dependsOn(build)

allprojects {
apply plugin: 'java'
apply plugin: 'base'

repositories {
mavenCentral()
}

dependencies {
testCompile 'junit:junit:4.12'
compile 'org.slf4j:slf4j-api:1.7.12'
testCompile group: 'ch.qos.logback', name: 'logback-classic', version: '0.9.26'
}

sourceSets {
test {
java.srcDir 'src/test/java'
}
integration {
java.srcDir 'src/test/integration/java'
resources.srcDir 'src/test/resources'
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
}
}

configurations {
integrationCompile.extendsFrom testCompile
integrationRuntime.extendsFrom testRuntime
}

task integration(type: Test, description: 'Runs the integration tests.', group: 'Verification') {
testClassesDirs = sourceSets.integration.output.classesDirs
classpath = sourceSets.integration.runtimeClasspath
}
test {
reports.html.enabled = true
}
clean {
file('out').deleteDir()
}

}

最佳答案

clean {
file("myApp-app/${rootProject.name}.jar").delete()
}

这样每次都会删除评估文件,这不是你想要的。将其更改为:

clean {
delete "myApp-app/${rootProject.name}.jar"
}

这会配置清理任务并添加要在执行时删除的 JAR。

关于java - Gradle 清理并复制 JAR 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49413227/

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