maven parent pom不会从nexus下载依赖项

时间:2017-04-28 07:51:57

标签: maven dependencies nexus

我已经设置了一个nexus,我可以将我的工件部署到我的nexus repo。但是,当我在我的父母pom上启动mvn编译时,它不会从我的子模块下载工件。当我从子模块启动一个mvn编译时,它工作正常,它从子模块下载我的依赖项。

所以来自父级的mvn clean编译不会从nexus下载ecs-data-contract依赖项,但是ecs-webservice的mvn clean编译会下载ecs-data-contract依赖项。

我错过了什么或做错了什么?

非常感谢

这是我的父母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>nl.ict.psa</groupId>
    <artifactId>psa-parent</artifactId>
    <version>1.0.0.0</version>
    <packaging>pom</packaging>
    <name>PSA Parent</name>

    <distributionManagement>
        <repository>
            <id>maven-public</id>
            <url>http://localhost:9090/repository/maven-public/</url>
            <name>PSA repository</name>
        </repository>
    </distributionManagement>

    <!-- settings -->
    <properties>
        <encoding>UTF-8</encoding>
        <jdk.version>1.8</jdk.version>
        <commons-lang3-version>3.5</commons-lang3-version>
        <commons-cli-version>1.2</commons-cli-version>
        <log4j-version>2.6.2</log4j-version>
        <junit-version>4.12</junit-version>
    </properties>

    <modules>
        <module>ecs-data-contract</module>
        <module>ecs-webservice</module>
    </modules>

    <dependencyManagement>
        <dependencies>
            <!-- common dependencies -->
            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-lang3</artifactId>
                <version>${commons-lang3-version}</version>
            </dependency>
            <dependency>
                <groupId>org.apache.logging.log4j</groupId>
                <artifactId>log4j-api</artifactId>
                <version>${log4j-version}</version>
            </dependency>
            <dependency>
                <groupId>org.apache.logging.log4j</groupId>
                <artifactId>log4j-core</artifactId>
                <version>${log4j-version}</version>
            </dependency>
            <dependency>
                <groupId>commons-cli</groupId>
                <artifactId>commons-cli</artifactId>
                <version>${commons-cli-version}</version>
            </dependency>

            <!-- Test dependencies -->
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>${junit-version}</version>
                <scope>test</scope>
            </dependency>

        </dependencies>
    </dependencyManagement>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.sonatype.plugins</groupId>
                    <artifactId>nexus-staging-maven-plugin</artifactId>
                    <version>1.5.1</version>
                    <executions>
                        <execution>
                            <id>default-deploy</id>
                            <phase>deploy</phase>
                            <goals>
                                <goal>deploy</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <serverId>nexus</serverId>
                        <nexusUrl>http://localhost:9090/repository/psa-public-release/</nexusUrl>
                        <skipStaging>true</skipStaging>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>${jdk.version}</source>
                        <target>${jdk.version}</target>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

</project>

这是我的settings.xml

 <settings>
  <mirrors>
    <mirror>
      <!--This sends everything else to /public -->
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
      <url>http://localhost:9090/repository/maven-public/</url>
    </mirror>
  </mirrors>
  <servers>
    <server>
      <id>nexus</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
  </servers>  
  <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>
</settings>

3 个答案:

答案 0 :(得分:0)

你的2个模块应该在同一个父项下,整个项目(父项和2个子项/模块)应该自己构建。

您的2个模块应指定其父级,而不是设置版本或组:

ecs-data-contract pom应如下所示:

<parent>
    <groupId>nl.ict.psa</groupId>
    <artifactId>psa-parent</artifactId>
    <version>1.0.0.0</version>
</parent>
<artifactId>ecs-data-contract</artifactId>

ecs-webservice pom应如下所示:

<parent>
    <groupId>nl.ict.psa</groupId>
    <artifactId>psa-parent</artifactId>
    <version>1.0.0.0</version>
</parent>
<artifactId>ecs-webservice</artifactId>

然后,当ecs-webservice想要依赖于ecs-data-contract时,依赖关系将如下所示:

<dependency>
  <groupId>nl.ict.psa</groupId>
  <artifactId>ecs-data-contract</artifactId>
  <version>${project.version}</version>
</dependency>

答案 1 :(得分:0)

尝试从父pom中删除整个nexus-staging-maven-plugin插件配置。

我和你有一个类似的项目bc-framework。在parant项目中运行mvn compile时,可以正常下载所有依赖项。区别在于我没有nexus-staging-maven-plugin配置。

答案 2 :(得分:0)

很晚了,但我也犯了类似的错误。

解决方案::删除我的本地.m2 /存储库文件夹。

说明:.m2 /存储库文件夹已损坏

我在这一行发现了这个解决方案:

mvn clean package -Dmaven.repo.local=/tmp/m2

模拟一个空或新的 .m2 /存储库文件夹。

此后,我的依赖项开始下载。