我在Gradle中创建了2个Jar任务。一种普通班:
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中运行build:
$ 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个罐子?我尝试编写释放任务,但无论如何它不起作用:
tasks.register('build-release') {
dependsOn 'common-jar'
dependsOn 'project-jar'
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。