gpt4 book ai didi

java - Gradle:一次运行2个Jar任务仅生成一个jar文件

转载 作者:行者123 更新时间:2023-12-01 19:12:10 29 4
gpt4 key购买 nike

我在 Gradle 中创建了 2 个 Jar 任务。一个用于公共(public)类:

tasks.register('compile-common', JavaCompile) {
description = 'compile common classes'
source = sourceSets.main.scala.srcDirs.collect { it.toPath().resolve('my/artifact/common').toFile() }
classpath = sourceSets.main.compileClasspath
destinationDir = project.buildDir.toPath().resolve('classes.common').toFile()
}

tasks.register('common-jar', Jar) {
description = 'build common jar'
manifest {
attributes 'Build': project.version
}
archivesBaseName = project.name + '-common'
from project.buildDir.toPath().resolve('classes.common').toFile()
dependsOn 'compile-common'
}

对于具有自定义名称的完整项目:

tasks.register('project-jar', Jar) {
description = 'build project jar'
manifest {
attributes 'Build': project.version
}
archivesBaseName = project.name
from sourceSets.main.output
dependsOn 'compileScala'
}

之后我在 bash 中运行构建:

$ rm -rf build/libs; ./gradlew project-jar common-jar; ls -l build/libs
-rw-r--r-- 1 a.iatsuk staff 265619 Dec 24 14:52 project-common-0.3.61.jar

$ rm -rf build/libs; ./gradlew common-jar project-jar ; ls -l build/libs
-rw-r--r--@ 1 a.iatsuk staff 11482514 Dec 24 14:53 project-0.3.61.jar

$ rm -rf build/libs; ./gradlew common-jar; ./gradlew project-jar; ls -l build/libs
-rw-r--r-- 1 a.iatsuk staff 11482514 Dec 24 14:54 project-0.3.61.jar
-rw-r--r-- 1 a.iatsuk staff 265619 Dec 24 14:54 project-common-0.3.61.jar

为什么我调用两个任务时都无法获取 2 个 jar?我尝试编写发布任务,但无论如何它都不起作用:

tasks.register('build-release') {
dependsOn 'common-jar'
dependsOn 'project-jar'
}

最佳答案

我删除了所有 = 符号,并将 archivesBaseName 替换为 baseName。我不知道为什么,但这个修复对我有帮助:

tasks.register('common-jar', Jar) {
description 'build common jar'
manifest {
attributes 'Build': project.version
}
baseName project.name + '-common'
from {
project.buildDir.toPath().resolve('classes.common').toFile()
}
dependsOn 'compile-common'
}

tasks.register('project-jar', Jar) {
description 'build project jar'
manifest {
attributes 'Build': project.version
}
baseName project.name
from {
sourceSets.main.output
}
dependsOn 'compileScala'
}

关于java - Gradle:一次运行2个Jar任务仅生成一个jar文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59468785/

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