我有一个带有8个子项目的gradle项目和一个配置好的shadowjar任务来创建一个"all“jar。toplevel项目的设置是为了对其所有子项目具有依赖关系,这将告诉shadowjar应该包括什么:
project(':') {
dependencies {
compile project(':jfxtras-agenda')
compile project(':jfxtras-common')
compile project(':jfxtras-controls')
compile project(':jfxtras-icalendarfx')
compile project(':jfxtras-icalendaragenda')
compile project(':jfxtras-menu')
compile project(':jfxtras-gauge-linear')
compile project(':jfxtras-font-roboto')
}
}
shadowJar {
classifier = null // do not append "-all", so the generated shadow jar replaces the existing jfxtras-all.jar (instead of generating jfxtras-all-all.jar)
}这很好,但是maven中心拒绝all jar,因为它没有关联的源和javadocs。
我如何告诉gradle也生成源和javadoc?ShadowJar的文档说,默认情况下,它应该这样做。
发布于 2017-11-24 21:52:42
影子插件似乎没有构建胖源/javadocs jars的特性。
下面,我将提供一些简短的任务(javadocJar和sourcesJar)来构建胖javadoc和源jars。它们被链接到始终在shadowJar之后执行。但它不依赖影子jar插件。
subprojects {
apply plugin: 'java'
}
// Must be BELOW subprojects{}
task alljavadoc(type: Javadoc) {
source subprojects.collect { it.sourceSets.main.allJava }
classpath = files(subprojects.collect { it.sourceSets.main.compileClasspath })
destinationDir = file("${buildDir}/docs/javadoc")
}
task javadocJar(type: Jar, dependsOn: alljavadoc) {
classifier = 'javadoc'
from alljavadoc.destinationDir
}
task sourcesJar(type: Jar) {
classifier = 'sources'
from subprojects.collect { it.sourceSets.main.allSource }
}
shadowJar.finalizedBy javadocJar
shadowJar.finalizedBy sourcesJar注意,subprojects部分是必需的,即使您已经在子项目中应用了java插件。
还要注意,它不包括您的子项目可能依赖的第三方库的javadocs。但通常情况下你可能都不想这么做。
发布于 2021-12-24 23:09:33
这是一条旧的帖子,但我正在发布我的解决方案,因为它比上面的要容易得多,而且我已经确认了它的工作原理:
plugins {
id 'com.github.johnrengelman.shadow' version '7.1.0'
id 'signing'
id 'maven-publish'
}
// If using Spring Boot, this is needed
jar.enabled = true
jar.dependsOn shadowJar
java {
withJavadocJar()
withSourcesJar()
}
// Remove the -all extension from the "fat" Jar, or it can't be used
// when published to Maven Central.
shadowJar {
archiveClassifier.set('')
}
// The contents of this section are described here:
// https://docs.gradle.org/current/userguide/publishing_maven.html
publishing {
publications {
jwtopaLibrary(MavenPublication) {
artifactId = 'jwt-opa'
artifacts = [ shadowJar, javadocJar, sourcesJar ]
pom {
// etc. ...
}
// Signs the `publication` generated above with the name `jwtopaLibrary`
// Signing plugin, see: https://docs.gradle.org/current/userguide/signing_plugin.html#signing_plugin
signing {
sign publishing.publications.jwtopaLibrary
}在任何地方都不清楚,需要在几个地方收集信息,但是要使signing插件正常工作,您需要short form十六进制键ID:
# gradle.properties
# The `signing` plugin documentation is less than helpful;
# however, this is the magic incantation to find the `keyId`:
#
# gpg --list-signatures --keyid-format 0xshort
#
# The key also needs to be distributed to public GPG servers:
#
# gpg --keyserver keyserver.ubuntu.com --send-keys 123...fed
#
# In all cases, we need to use the values from the `pub` key.
signing.keyId=0x1234abcde然后,这只是一个运行./gradlew publish和魔术发生的问题(其实,你仍然必须去Sonatype存储库,做“关闭和发布舞蹈”,但是你知道,不管怎样)。
https://stackoverflow.com/questions/44787645
复制相似问题