java - 无法使用 Gradle 将工件上传到 Nexus Sonatype

标签 java intellij-idea gradle build.gradle nexus

我正在尝试开始使用 Nexus(版本 2.X)作为本地 Maven 存储库。 我一直在寻找一种将我的依赖项自动上传到 Nexus 的方法,但我无法让它工作。

使用 Gradle 4.1、Java 8 和 InteliJIdea(如果有必要的话)。

我的build.gradle文件如下:

group 'myGroupName'
version '1.0-SNAPSHOT'

apply plugin: 'java'
apply plugin:'maven'

sourceCompatibility = 1.8

repositories {
    maven {
        url "http://localhost:8081/nexus/content/repositories/thirdparty/"
    }
}

dependencies {
    testCompile 'org.testng:testng:6.9.4'
    compile group: 'org.apache.commons', name: 'commons-math3', version: '3.5'
    compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.6'
}

uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: "http://localhost:8081/nexus/content/repositories/thirdparty/") {
                authentication(userName: "admin", password: "admin123")
            }
        }
    }
}

我已手动上传 commons-math3-3.5.jar,并尝试使用 uploadArchives 自动上传 commons-lang3-3.6 .

我得到的错误是

* What went wrong:
Could not resolve all files for configuration ':compileClasspath'.
> Could not resolve org.apache.commons:commons-lang3:3.6.
  Required by:
      project :
   > Could not resolve org.apache.commons:commons-lang3:3.6.
      > Could not get resource 'http://localhost:8081/nexus/content/repositories/thirdparty/org/apache/commons/commons-lang3/3.6/commons-lang3-3.6.pom'.
         > Could not GET 'http://localhost:8081/nexus/content/repositories/thirdparty/org/apache/commons/commons-lang3/3.6/commons-lang3-3.6.pom'. Received status code 401 from server: Unauthorized

我还尝试过 compile "org.apache.commons:commons-lang3:3.6" 而不是 compile group: 'org.apache.commons', name: 'commons-lang3 ',版本:'3.6',与 Nexus Build Grade Example 匹配,并且还尝试添加

task wrapper( type: Wrapper, description: "create a gradlew" ) {
gradleVersion = '4.1'
}

但是没有成功。

有人知道我错过了什么吗?

最佳答案

没有完整的错误消息,但看起来您在编译阶段出现了错误。我认为它无法从编译所需的 Nexus 依赖项下载。尝试在存储库部分添加jcenter()来解决这个问题。 或者,您可以在 Maven 配置中为您的 Nexus 提供有效的凭据

repositories {
    maven {
        url "http://localhost:8081/nexus/content/repositories/thirdparty/"
        credentials {
                username "user"
                password "password"
        }
    }
}

我建议也使用 maven-publish 插件 https://docs.gradle.org/current/userguide/publishing_maven.html

顺便说一句,您使用的示例已经过时了。我建议使用 Gradle 附带的示例或来自其文档的示例。

关于java - 无法使用 Gradle 将工件上传到 Nexus Sonatype,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46541289/

相关文章:

java - 构建网页内容过滤器

java - 适用于 Java 的 vaadin 和 google 应用引擎

java - 重复的数组列表条目

java - IntelliJ - 等于之前不必要的 'null' 检查

java - 在不同计算机之间同步 IntelliJ 项目

android - Gradle 错误使用 fbutton

java - 操作系统 : Why can't Java read my environment variables?

java - 错误 : Gradle: error: package javax. 邮件不存在

java - 在项目或库中找不到 list 中引用的类

rest - 在另一个 build.gradle 项目中执行测试