我是新手,正在尝试使用Gradle发布一个简单的项目到Maven中央仓库。我的build.gradle脚本与他们文档中的示例几乎相同,但是我的主要/编译JAR没有被上传。源代码JAR、Java文档JAR等都可以上传,但编译后的文件却不能上传。
在本地发布(publishToMavenLocal)时,一切正常。我注意到我正在使用版本6.0.1,并且使用publishMavenJavaPublicationToMavenRepository来发布到中央仓库。
我错过了什么?如何将我的编译JAR上传到中央仓库?
更新:我刚刚意识到POM也没有被上传。
这是完整的build.gradle:
在本地发布(publishToMavenLocal)时,一切正常。我注意到我正在使用版本6.0.1,并且使用publishMavenJavaPublicationToMavenRepository来发布到中央仓库。
我错过了什么?如何将我的编译JAR上传到中央仓库?
更新:我刚刚意识到POM也没有被上传。
这是完整的build.gradle:
plugins {
id 'java-library'
id 'maven-publish'
id 'signing'
}
repositories {
jcenter()
mavenCentral()
}
dependencies {
implementation 'com.squareup.okhttp3:okhttp:4.0.1'
implementation 'com.squareup.moshi:moshi:1.9.1'
implementation 'com.squareup.moshi:moshi-adapters:1.9.1'
implementation 'com.google.guava:guava:28.0-jre'
api 'org.apache.commons:commons-math3:3.6.1'
testImplementation 'junit:junit:4.12'
}
group = 'com.acme'
version = '0.0.1-SNAPSHOT'
ext.isReleaseVersion = !version.endsWith("SNAPSHOT")
java {
withJavadocJar()
withSourcesJar()
}
publishing {
publications {
mavenJava(MavenPublication) {
artifactId = 'thttpd'
from components.java
pom {
name = 'thttpd'
licenses {
license {
name = 'The MIT License (MIT)'
url = 'https://opensource.org/licenses/MIT'
}
}
scm {
connection = 'scm:git:https://acme.com'
developerConnection = 'scm:git:https://acme.com'
url = 'https://acme.com'
}
}
}
}
repositories {
// Maven Central
maven {
def releasesRepoUrl = 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
def snapshotsRepoUrl = 'https://oss.sonatype.org/content/repositories/snapshots/'
url = isReleaseVersion ? releasesRepoUrl : snapshotsRepoUrl
credentials {
username = nexusUsername
password = nexusPassword
}
}
}
}
signing {
required { isReleaseVersion && gradle.taskGraph.hasTask("publish") }
if( required ) {
sign publishing.publications.mavenJava
}
}
withSourcesJar()
也没有帮助。 - Alexis