Gradle配置发布Java项目到Maven仓库的任务 Kotl

2023-04-20  本文已影响0人  FKYNvidia

本文使用API Token进行发布,只需替换authentication 和 credentials即可使用其他认证方式

  1. 在build.gradle.kts脚本中添加Maven发布插件
plugins {
    id("java")
    id("maven-publish")
    // other plugins
}
  1. 在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")
            }
        }
    }
}
上一篇 下一篇

猜你喜欢

热点阅读