我想知道如何在以 canonical 方式使用gradle构建的分发zip中包含自定义构建工件。我已经设法通过直接引用工件的路径来做到这一点,但我猜测有更好的方法来实现这一点:
task sourcesJar(type: Jar, dependsOn: tasks.classes) {
classifier 'sources'
from sourceSets.main.allSource
}
tasks.distZip.shouldRunAfter tasks.sourcesJar
tasks.distTar.shouldRunAfter tasks.sourcesJar
artifacts {
archives sourcesJar
}
distributions {
main {
contents {
from { "${libsDir}/${project.name}-${version}-sources.jar" }
}
}
}
如何根据其定义引用我的sources工件的名称,或者是否有更好的方法在分发中包含构建的工件?
答案 0 :(得分:1)
可能是例如:
apply plugin: 'java'
apply plugin: 'distribution'
task sourcesJar(type: Jar, dependsOn: tasks.classes) {
classifier 'sources'
from sourceSets.main.allSource
}
tasks.distZip.shouldRunAfter tasks.sourcesJar
tasks.distTar.shouldRunAfter tasks.sourcesJar
artifacts {
archives sourcesJar
}
distributions {
main {
contents {
from { tasks.sourcesJar.archivePath }
}
}
}
答案 1 :(得分:1)
您也可以直接引用jar任务:
distributions {
main {
contents {
from { sourcesJar }
}
}
}