本文使用API Token进行发布,只需替换authentication 和 credentials即可使用其他认证方式
- 在build.gradle.kts脚本中添加Maven发布插件
plugins {
id("java")
id("maven-publish")
// other plugins
}
- 在build.gradle.kts脚本中添加publishing
publishing {
publications {
create<MavenPublication>("maven") {
groupId = "${group-id}"
artifactId = "${artifact-id}"
version = "${version-number}"
from(components["java"])
}
}
// other settings of publication
repositories {
maven {
name = "${maven_repo_name}" // Optional, this will be used in generate publishing task name
url = uri("${maven_repo_url}")
//isAllowInsecureProtocol = true // For http protocal server, this is needed for insecure url
credentials(HttpHeaderCredentials::class) {
name = "Authorization"
value = "token ${token}"
}
authentication {
create<HttpHeaderAuthentication>("header")
}
}
}
}