Gradle 无法解析私有 Nexus 3 存储库的依赖关系

发布于 2025-01-09 02:02:13 字数 4269 浏览 0 评论 0原文

我正在尝试构建一个使用私有 Nexus 存储库中的库的 gradle 项目。

版本:

  • Gradle 7.4
  • Nexus OSS 3.37

这是 build.gradle

plugins {
    id 'java'
}

group 'io.riccardopedrielli'
version '1.0.0'

repositories {
    maven {
        url 'https://nexus.riccardopedrielli.io/repository/maven-releases/'
        credentials {
            username '<myuser>'
            password '<mypass>'
        }
    }
    mavenCentral()
}

dependencies {
    implementation 'io.riccardopedrielli.mylib:1.0.0'
}

当我运行 ./gradlew build 时,出现以下错误:

* What went wrong:
Execution failed for task ':compileJava'.
> Could not resolve all files for configuration ':compileClasspath'.
   > Could not find io.riccardopedrielli.mylib:1.0.0:.
     Required by:
         project :

添加 --debug 我看到这些与 lib 相关的行:


[org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.builder.NodeState] dependency: io.riccardopedrielli.mylib:1.0.0 from-conf: implementation to-conf: null is filtered.
[org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.builder.NodeState] dependency: io.riccardopedrielli.mylib:1.0.0 from-conf: implementation to-conf: null is filtered.
[org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.builder.NodeState] dependency: io.riccardopedrielli.mylib:1.0.0 from-conf: implementation to-conf: null is filtered.
[org.gradle.api.internal.artifacts.ivyservice.ivyresolve.RepositoryChainComponentMetaDataResolver] Attempting to resolve component for io.riccardopedrielli.mylib:1.0.0: using repositories [maven, MavenRepo]
[org.gradle.api.internal.artifacts.ivyservice.ivyresolve.CachingModuleComponentRepository] Detected non-existence of module 'io.riccardopedrielli.mylib:1.0.0:' in resolver cache 'maven'
[org.gradle.api.internal.artifacts.ivyservice.ivyresolve.CachingModuleComponentRepository] Detected non-existence of module 'io.riccardopedrielli.mylib:1.0.0:' in resolver cache 'MavenRepo'
[org.gradle.api.internal.artifacts.repositories.resolver.ExternalResourceResolver] No meta-data file or artifact found for module 'io.riccardopedrielli.mylib:1.0.0:' in repository 'maven'.
[org.gradle.api.internal.artifacts.ivyservice.modulecache.PersistentModuleMetadataCache] Recording absence of module descriptor in cache: io.riccardopedrielli.mylib:1.0.0: [changing = false]
[org.gradle.api.internal.artifacts.repositories.resolver.ExternalResourceResolver] No meta-data file or artifact found for module 'io.riccardopedrielli.mylib:1.0.0:' in repository 'MavenRepo'.
[org.gradle.api.internal.artifacts.ivyservice.modulecache.PersistentModuleMetadataCache] Recording absence of module descriptor in cache: io.riccardopedrielli.mylib:1.0.0: [changing = false]

相反,如果我将 maven 与以下 pom.xml 一起使用,则一切正常:

<?xml version="1.0" encoding="UTF-8"?>
<project
    xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>io.riccardopedrielli</groupId>
    <artifactId>myapp</artifactId>
    <version>1.0.0</version>

    <dependencies>
        <dependency>
            <groupId>io.riccardopedrielli</groupId>
            <artifactId>mylib</artifactId>
            <version>1.0.0</version>
        </dependency>
    </dependencies>

    <repositories>
        <repository>
            <id>central</id>
            <url>http://repo1.maven.org/maven2</url>
        </repository>
        <repository>
            <id>localNexus</id>
            <url>https://nexus.riccardopedrielli.io/repository/maven-releases/</url>
        </repository>
    </repositories>

    <build>
        ...
    </build>

    <properties>
        ...
    </properties>
</project>

由于 Nexus 存储库与 maven 兼容,我想我错过了某物在build.gradle中。

I'm trying to build a gradle project the uses a library from a private Nexus repository.

Versions:

  • Gradle 7.4
  • Nexus OSS 3.37

This is the build.gradle:

plugins {
    id 'java'
}

group 'io.riccardopedrielli'
version '1.0.0'

repositories {
    maven {
        url 'https://nexus.riccardopedrielli.io/repository/maven-releases/'
        credentials {
            username '<myuser>'
            password '<mypass>'
        }
    }
    mavenCentral()
}

dependencies {
    implementation 'io.riccardopedrielli.mylib:1.0.0'
}

When I run ./gradlew build I get the following error:

* What went wrong:
Execution failed for task ':compileJava'.
> Could not resolve all files for configuration ':compileClasspath'.
   > Could not find io.riccardopedrielli.mylib:1.0.0:.
     Required by:
         project :

Adding --debug i see these lines related to the lib:


[org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.builder.NodeState] dependency: io.riccardopedrielli.mylib:1.0.0 from-conf: implementation to-conf: null is filtered.
[org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.builder.NodeState] dependency: io.riccardopedrielli.mylib:1.0.0 from-conf: implementation to-conf: null is filtered.
[org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.builder.NodeState] dependency: io.riccardopedrielli.mylib:1.0.0 from-conf: implementation to-conf: null is filtered.
[org.gradle.api.internal.artifacts.ivyservice.ivyresolve.RepositoryChainComponentMetaDataResolver] Attempting to resolve component for io.riccardopedrielli.mylib:1.0.0: using repositories [maven, MavenRepo]
[org.gradle.api.internal.artifacts.ivyservice.ivyresolve.CachingModuleComponentRepository] Detected non-existence of module 'io.riccardopedrielli.mylib:1.0.0:' in resolver cache 'maven'
[org.gradle.api.internal.artifacts.ivyservice.ivyresolve.CachingModuleComponentRepository] Detected non-existence of module 'io.riccardopedrielli.mylib:1.0.0:' in resolver cache 'MavenRepo'
[org.gradle.api.internal.artifacts.repositories.resolver.ExternalResourceResolver] No meta-data file or artifact found for module 'io.riccardopedrielli.mylib:1.0.0:' in repository 'maven'.
[org.gradle.api.internal.artifacts.ivyservice.modulecache.PersistentModuleMetadataCache] Recording absence of module descriptor in cache: io.riccardopedrielli.mylib:1.0.0: [changing = false]
[org.gradle.api.internal.artifacts.repositories.resolver.ExternalResourceResolver] No meta-data file or artifact found for module 'io.riccardopedrielli.mylib:1.0.0:' in repository 'MavenRepo'.
[org.gradle.api.internal.artifacts.ivyservice.modulecache.PersistentModuleMetadataCache] Recording absence of module descriptor in cache: io.riccardopedrielli.mylib:1.0.0: [changing = false]

Instead, if I use maven with the following pom.xml, everything works fine:

<?xml version="1.0" encoding="UTF-8"?>
<project
    xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>io.riccardopedrielli</groupId>
    <artifactId>myapp</artifactId>
    <version>1.0.0</version>

    <dependencies>
        <dependency>
            <groupId>io.riccardopedrielli</groupId>
            <artifactId>mylib</artifactId>
            <version>1.0.0</version>
        </dependency>
    </dependencies>

    <repositories>
        <repository>
            <id>central</id>
            <url>http://repo1.maven.org/maven2</url>
        </repository>
        <repository>
            <id>localNexus</id>
            <url>https://nexus.riccardopedrielli.io/repository/maven-releases/</url>
        </repository>
    </repositories>

    <build>
        ...
    </build>

    <properties>
        ...
    </properties>
</project>

Since the Nexus repository is ok with maven, I think I'm missing something in build.gradle.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

世界和平 2025-01-16 02:02:13

尝试在maven中添加metadataSources,如下例所示:

maven {
   url = uri("nexus-maven-url")
    metadataSources
    {
        mavenPom();
        artifact()
    }
   }
}

Try by adding metadataSources inside maven, as shown in the example below:

maven {
   url = uri("nexus-maven-url")
    metadataSources
    {
        mavenPom();
        artifact()
    }
   }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文