[英]Why my maven project is not able to resolve dependency from private sonatype-nexus maven repository?
I have deployed a private maven repository on an aws ec2 instance.我已经在 aws ec2 实例上部署了一个私有 maven 存储库。 And I am able to deploy few artefacts successfully as shown.
如图所示,我能够成功部署一些人工制品。
My settings.xml looks like following我的 settings.xml 如下所示
<settings>
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://maven.tarkshala.com:10081/repository/maven-tarkshala-central/</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<!--Enable snapshots for the built in central repo to direct -->
<!--all requests to nexus via the mirror -->
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<!--make the profile active all the time -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
<servers>
<server>
<id>nexus</id>
<username>admin</username>
<password>tarkshala</password>
</server>
</servers>
</settings>
My project pom file looks like this我的项目 pom 文件看起来像这样
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.tarkshala.dhaba</groupId>
<artifactId>user-service</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>UserService</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<dropwizard.version>2.1.4</dropwizard.version>
<dropwizard.guicey.version>5.4.1</dropwizard.guicey.version>
<dropwizard.swagger.version>2.0.16-SNAPSHOT</dropwizard.swagger.version>
<lombok.version>1.18.24</lombok.version>
<db.sharding.bundle.version>2.0.28-5</db.sharding.bundle.version>
<mariadb.version>3.1.0</mariadb.version>
<mainClass>com.tarkshala.dhaba.UserServiceApplication</mainClass>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-dependencies</artifactId>
<version>${dropwizard.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-hibernate</artifactId>
</dependency>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-db</artifactId>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
</dependency>
<dependency>
<groupId>com.tarkshala</groupId>
<artifactId>dropwizard-swagger</artifactId>
<version>2.0.16-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</dependency>
<dependency>
<groupId>ru.vyarus</groupId>
<artifactId>dropwizard-guicey</artifactId>
<version>${dropwizard.guicey.version}</version>
</dependency>
<dependency>
<groupId>io.appform.dropwizard.sharding</groupId>
<artifactId>db-sharding-bundle</artifactId>
<version>${db.sharding.bundle.version}</version>
</dependency>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>${mariadb.version}</version>
</dependency>
<dependency>
<groupId>com.tarkshala</groupId>
<artifactId>tarkshala-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.tarkshala.dhaba</groupId>
<artifactId>userservice-models</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.4.0</version>
<configuration>
<createDependencyReducedPom>true</createDependencyReducedPom>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>${mainClass}</mainClass>
</transformer>
</transformers>
<!-- exclude signed Manifests -->
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>${mainClass}</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.4.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration><source>9</source><target>9</target></configuration></plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>9</source>
<target>9</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.4.1</version>
<configuration>
<dependencyLocationsEnabled>false</dependencyLocationsEnabled>
<dependencyDetailsEnabled>false</dependencyDetailsEnabled>
</configuration>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.4.1</version>
</plugin>
</plugins>
</reporting>
<profiles>
<profile>
<id>java11+</id>
<activation>
<jdk>[11,)</jdk>
</activation>
<properties>
<!--
Workaround for "javadoc: error - The code being documented uses modules but the packages
defined in https://docs.oracle.com/javase/8/docs/api/ are in the unnamed module."
-->
<maven.javadoc.skip>true</maven.javadoc.skip>
</properties>
</profile>
</profiles>
</project>
But as I try to build it using mvn clean install
it fails because of not able to resolve dependency with following error:但是当我尝试使用
mvn clean install
构建它时,它失败了,因为无法解决依赖关系并出现以下错误:
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.395 s
[INFO] Finished at: 2023-01-15T16:22:06+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project user-service: Could not resolve dependencies for project com.tarkshala.dhaba:user-service:jar:1.0-SNAPSHOT: The following artifacts could not be resolved: com.tarkshala:dropwizard-swagger:jar:2.0.16-SNAPSHOT, com.tarkshala:tarkshala-common:jar:1.0-SNAPSHOT: com.tarkshala:dropwizard-swagger:jar:2.0.16-SNAPSHOT was not found in http://maven.tarkshala.com:10081/repository/maven-tarkshala-central/ during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of nexus has elapsed or updates are forced -> [Help 1]
This is happening because my artefact is present in maven-snapshots
not in maven-tarkshala-central
.发生这种情况是因为我的人工制品存在于
maven-snapshots
而不是maven-tarkshala-central
。
What should I change to resolve dependencies from both?我应该更改什么以解决两者的依赖关系?
This failure was cached in the local repository and resolution is not reattempted until the update interval of nexus has elapsed or updates are forced
~/.mvn/
and remove the io.dropwizard
folder. ~/.mvn/
并删除io.dropwizard
文件夹。mvn clean install -U
mvn clean install -U
构建 I figured it out finally.我终于想通了。 Basically nexus repository system has three types as following.
基本上,nexus 存储库系统有以下三种类型。
maven-tarkshala-central
maven-tarkshala-central
maven-snapshots
and maven-releases
.maven-snapshots
和maven-releases
。 My settings.xml was pointing to proxy, so it was able to resolve all external dependencies but not able to resolve private dependencies.我的 settings.xml 指向代理,因此它能够解析所有外部依赖项但无法解析私有依赖项。 If I make it point one of the hosted it resolves private but not central.
如果我将它指向托管之一,它会解析为私有但不是中央。
maven-tarkshala-central, maven-snapshots, maven-releases
get available into this repo as shown in screenshot.maven-tarkshala-central, maven-snapshots, maven-releases
可用的所有依赖项都可用于此 repo,如屏幕截图所示。 Check the members that are available in group, mind the sequence.检查组中可用的成员,注意顺序。
Update settings.xml to use the group repo url as following更新 settings.xml 以使用组 repo url,如下所示
<settings>
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://maven.tarkshala.com:10081/repository/maven-public/</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<!--Enable snapshots for the built in central repo to direct -->
<!--all requests to nexus via the mirror -->
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<!--make the profile active all the time -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
<servers>
<server>
<id>nexus</id>
<username>admin</username>
<password>tarkshala</password>
</server>
</servers>
</settings>
And now happy building with mvn clean install
:)现在很高兴使用
mvn clean install
构建 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.