简体   繁体   English

发布到 Sonatype 时出错,因为“repositoryUrl”为空

[英]Error publishing to Sonatype because "repositoryUrl" is null

I've been trying to publish a project to Sonatype's repository, but I got an error and I can't find the solution online.我一直在尝试将项目发布到 Sonatype 的存储库,但出现错误,而且我无法在线找到解决方案。

I have the following publishing block on my build.gradle.kts file:我的build.gradle.kts文件中有以下publishing块:

publishing {
    publications {
        create<MavenPublication>("mavenJava") {
            pom {
                name.set("Keen")
                description.set("A genetic algorithm framework for Kotlin")
                url.set("https://github.com/r8vnhill/keen")
                licenses {
                    license {
                        name.set("Attribution 4.0 International (CC BY 4.0)")
                        url.set("https://creativecommons.org/licenses/by/4.0/legalcode")
                    }
                }
            }
            groupId = "cl.ravenhill"
            artifactId = "keen"
            version = projectVersion
            from(components["java"])
        }
    }
    repositories {
        maven {
            name = "sonatype"
            if (version.toString().endsWith("SNAPSHOT")) {
                maven("https://s01.oss.sonatype.org/content/repositories/snapshots/") {
                    name = "ossrh"
                    credentials(PasswordCredentials::class)
                }
            } else {
                maven("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/") {
                    name = "ossrh"
                    credentials(PasswordCredentials::class)
                }
            }
        }
    }
}

And the error I've got:我得到的错误是:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':publishMavenJavaPublicationToSonatypeRepository'.
> Failed to publish publication 'mavenJava' to repository 'sonatype'
   > Cannot invoke "java.net.URI.getScheme()" because "repositoryUrl" is null

Any idea of what could be happening?知道会发生什么吗?

The repository called 'sonatype' doesn't have a URL.名为“sonatype”的存储库没有 URL。

Assuming the version is a snapshot version, eg 1.2.3-SNAPSHOT , what you've written is假设版本是快照版本,例如1.2.3-SNAPSHOT ,你写的是

repositories { 
  maven {
    name = "sonatype"
    
    maven("https://s01.oss.sonatype.org/content/repositories/snapshots/") { 
      name = "ossrh"
      credentials(PasswordCredentials::class)
    } 
  }
}

This is also equivalent to这也相当于

repositories { 
  maven {
    name = "sonatype"
  }
  maven("https://s01.oss.sonatype.org/content/repositories/snapshots/") { 
    name = "ossrh"
    credentials(PasswordCredentials::class)
  } 
}

So repository 'sonatype' has a name, but doesn't have a URL.所以存储库“sonatype”有一个名称,但没有 URL。

Gradle will create a publication task for each defined repository, even if the definition isn't valid (which can't be known ahead of time). Gradle 将为每个定义的存储库创建一个发布任务,即使该定义无效(无法提前知道)。 If you ran the Gradle task如果你运行了 Gradle 任务

./gradlew publishMavenJavaPublicationToOssrhRepository

it would succeed.它会成功的。

To correct the problem, remove the 'sonatype' repository.要更正此问题,请删除“sonatype”存储库。 It would also be more clear if you defined the target URL in a separate variable.如果您在单独的变量中定义目标 URL,也会更清楚。

val ossrhRepositoryUrl = if (version.toString().endsWith("SNAPSHOT")) {
  "https://s01.oss.sonatype.org/content/repositories/snapshots/"
} else {
  "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
}

publishing {
  repositories {
    maven(ossrhRepositoryUrl) {
      name = "ossrh"
      credentials(PasswordCredentials::class)
    }
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 由于 Hilt 错误,应用程序未初始化 - App not initializing because of Hilt error 无法无条件访问属性“窗口”,因为接收者可以为“空” - The property 'window' can't be unconditionally accessed because the receiver can be 'null' MongoDB - 无法调用 ClusterDescription.getConnectionMode() 因为 clusterDescription 是 null - MongoDB - Cannot invoke ClusterDescription.getConnectionMode() because clusterDescription is null Kotlin中的错误“不能为空” - Error “must not be null” in Kotlin Android:应用程序因演示者错误而崩溃? - Android: Application crashes because of presenter error? AndroidStudio 错误:条目中的空值:workingDir=null - AndroidStudio error: null value in entry: workingDir=null 检查 null 后显示 Null 安全错误 - Null safety error showing after checking for null 错误:“无法智能转换为字符串,因为“消息”是可变的属性” - Error: “Smart cast to string is impossible because ”message“ is a mutable property” java.lang.NullPointerException:无法调用“service”,因为“this.contentService”为空 - java.lang.NullPointerException: Cannot invoke "service" because "this.contentService" is null Camerax 视频捕获停止,因为 null object 参考上的“void android.media.MediaCodec.reset()” - Camerax Video capture stopping, because of 'void android.media.MediaCodec.reset()' on a null object reference
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM