美文网首页
Gradle配置发布Java项目到Maven仓库的任务 Kotl

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

作者: FKYNvidia | 来源:发表于2023-04-20 01:32 被阅读0次

本文使用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")
            }
        }
    }
}

相关文章

网友评论

      本文标题:Gradle配置发布Java项目到Maven仓库的任务 Kotl

      本文链接:https://www.haomeiwen.com/subject/xshrjdtx.html