指定SNAPSHOT版本

时间:2017-01-05 14:25:09

标签: java maven maven-3

我正在尝试构建一个maven项目,该项目声明了一个依赖项管理部分,其中pom依赖项具有SNAPSHOT版本。但是,除非我设置了非SNAPSHOT版本,否则它拒绝构建。

我的settings.xml定义了这个镜像,它包含了我需要的所有快照版本:

<mirrors>
  <mirror>
    <id>public</id>
    <url>http://repoHost:8081/nexus/content/groups/public/</url>
    <mirrorOf>*</mirrorOf>
  </mirror>
</mirrors>

以下是我认为是pom的相关部分:

<properties>
  <myArtifactId.version>1.0.0-SNAPSHOT</myArtifactId.version>
</properties>

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>myGroupId</groupId>
      <artifactId>myParentArtifactId</artifactId>
      <version>${myParentArtifactId.version}</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>

<dependencies>
  <dependency>
    <groupId>myGroupId</groupId>
    <artifactId>subproject1</artifactId>
  </dependency>
  <dependency>
    <groupId>myGroupId</groupId>
    <artifactId>subproject2</artifactId>
  </dependency>
  <dependency>
    <groupId>myGroupId</groupId>
    <artifactId>subproject3</artifactId>
  </dependency>
  <dependency>
    <groupId>myGroupId</groupId>
    <artifactId>subproject4</artifactId>
  </dependency>
  <dependency>
    <groupId>myGroupId</groupId>
    <artifactId>subproject5</artifactId>
  </dependency>
  <dependency>
    <groupId>myGroupId</groupId>
    <artifactId>subproject6</artifactId>
  </dependency>
</dependencies>

<distributionManagement>
  <snapshotRepository>
    <id>mySnapshots</id>
    <url>http://repoHost:8081/nexus/content/repositories/my-snapshots</url>
  </snapshotRepository>
  <repository>
    <id>myReleases</id>
    <url>http://repoHost:8081/nexus/content/repositories/my-releases</url>
  </repository>
</distributionManagement>

以下是我看到的错误,更新了行和列引用以匹配上面的pom代码段:

PS > mvn -U -X -e clean
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T17:41:47+01:00)
Maven home: C:\dev\java\apache-maven-3.3.9\bin\..
Java version: 1.8.0_112, vendor: Oracle Corporation
Java home: C:\dev\java\jdk1.8.0_112\jre
Default locale: sv_SE, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "dos"
[DEBUG] Created new class realm maven.api
[DEBUG] Importing foreign packages into class realm maven.api
...
[INFO] Scanning for projects...
[DEBUG] Using mirror public (http://repoHost:8081/nexus/content/groups/public/) for central (https://repo.maven.apache.org/maven2).
[DEBUG] Extension realms for project exampleGroupId:ptexample:jar:1.0.0-SNAPSHOT: (none)
[DEBUG] Looking up lifecyle mappings for packaging jar from ClassRealm[plexus.core, parent: null]
[DEBUG] Could not find metadata myGroupId:myParentArtifactId:1.0.0-SNAPSHOT/maven-metadata.xml in local (C:\Users\cb2\.m2\repository)
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[ERROR] Non-resolvable import POM: Could not find artifact myGroupId:myParentArtifactId:pom:1.0.0-SNAPSHOT @ line 7, column 21
[ERROR] 'dependencies.dependency.version' for myGroupId:subproject1:jar is missing. @ line 18, column 19
[ERROR] 'dependencies.dependency.version' for myGroupId:subproject2:jar is missing. @ line 22, column 19
[ERROR] 'dependencies.dependency.version' for myGroupId:subproject3:jar is missing. @ line 26, column 19
[ERROR] 'dependencies.dependency.version' for myGroupId:subproject4:jar is missing. @ line 30, column 19
[ERROR] 'dependencies.dependency.version' for myGroupId:subproject5:jar is missing. @ line 34, column 19
[ERROR] 'dependencies.dependency.version' for myGroupId:subproject6:jar is missing. @ line 38, column 19
 @
[ERROR] The build could not read 1 project -> [Help 1]
org.apache.maven.project.ProjectBuildingException: Some problems were encountered while processing the POMs:
[ERROR] Non-resolvable import POM: Could not find artifact myGroupId:myParentArtifactId:pom:1.0.0-SNAPSHOT @ line 7, column 21
[ERROR] 'dependencies.dependency.version' for myGroupId:subproject1:jar is missing. @ line 18, column 19
[ERROR] 'dependencies.dependency.version' for myGroupId:subproject2:jar is missing. @ line 22, column 19
[ERROR] 'dependencies.dependency.version' for myGroupId:subproject3:jar is missing. @ line 26, column 19
[ERROR] 'dependencies.dependency.version' for myGroupId:subproject4:jar is missing. @ line 30, column 19
[ERROR] 'dependencies.dependency.version' for myGroupId:subproject5:jar is missing. @ line 34, column 19
[ERROR] 'dependencies.dependency.version' for myGroupId:subproject6:jar is missing. @ line 38, column 19

        at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:422)
        at org.apache.maven.graph.DefaultGraphBuilder.collectProjects(DefaultGraphBuilder.java:419)
        at org.apache.maven.graph.DefaultGraphBuilder.getProjectsForMavenReactor(DefaultGraphBuilder.java:410)
        at org.apache.maven.graph.DefaultGraphBuilder.build(DefaultGraphBuilder.java:83)
        at org.apache.maven.DefaultMaven.buildGraph(DefaultMaven.java:491)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:219)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
[ERROR]
[ERROR]   The project exampleGroupId:ptexample:1.0.0-SNAPSHOT (C:\projects\bitbucket\EW\pt-example\pom.xml) has 7 errors
[ERROR]     Non-resolvable import POM: Could not find artifact myGroupId:myParentArtifactId:pom:1.0.0-SNAPSHOT @ line 7, column 21 -> [Help 2]
org.apache.maven.model.resolution.UnresolvableModelException: Could not find artifact myGroupId:myParentArtifactId:pom:1.0.0-SNAPSHOT
        at org.apache.maven.project.ProjectModelResolver.resolveModel(ProjectModelResolver.java:197)
        at org.apache.maven.model.building.DefaultModelBuilder.importDependencyManagement(DefaultModelBuilder.java:1192)
        at org.apache.maven.model.building.DefaultModelBuilder.build(DefaultModelBuilder.java:455)
        at org.apache.maven.model.building.DefaultModelBuilder.build(DefaultModelBuilder.java:421)
        at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:620)
        at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:411)
        at org.apache.maven.graph.DefaultGraphBuilder.collectProjects(DefaultGraphBuilder.java:419)
        at org.apache.maven.graph.DefaultGraphBuilder.getProjectsForMavenReactor(DefaultGraphBuilder.java:410)
        at org.apache.maven.graph.DefaultGraphBuilder.build(DefaultGraphBuilder.java:83)
        at org.apache.maven.DefaultMaven.buildGraph(DefaultMaven.java:491)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:219)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.eclipse.aether.resolution.ArtifactResolutionException: Could not find artifact myGroupId:myParentArtifactId:pom:1.0.0-SNAPSHOT
        at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:444)
        at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifacts(DefaultArtifactResolver.java:246)
        at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifact(DefaultArtifactResolver.java:223)
        at org.eclipse.aether.internal.impl.DefaultRepositorySystem.resolveArtifact(DefaultRepositorySystem.java:294)
        at org.apache.maven.project.ProjectModelResolver.resolveModel(ProjectModelResolver.java:193)
        ... 23 more
Caused by: org.eclipse.aether.transfer.ArtifactNotFoundException: Could not find artifact myGroupId:myParentArtifactId:pom:1.0.0-SNAPSHOT
        at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:434)
        ... 27 more
[ERROR]     'dependencies.dependency.version' for myGroupId:subproject1:jar is missing. @ line 18, column 19
[ERROR]     'dependencies.dependency.version' for myGroupId:subproject2:jar is missing. @ line 22, column 19
[ERROR]     'dependencies.dependency.version' for myGroupId:subproject3:jar is missing. @ line 26, column 19
[ERROR]     'dependencies.dependency.version' for myGroupId:subproject4:jar is missing. @ line 30, column 19
[ERROR]     'dependencies.dependency.version' for myGroupId:subproject5:jar is missing. @ line 34, column 19
[ERROR]     'dependencies.dependency.version' for myGroupId:subproject6:jar is missing. @ line 38, column 19
[ERROR]
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException

输出中的链接确实提供了一些线索,但无论如何我无法解决问题。

如果我只是更新以使用特定版本,我可以让它工作:

<properties>
  <myArtifactId.version>1.0.0</myArtifactId.version>
</properties>

但是消除对myParentArtifactId依赖项的引用并在所有指定的依赖项上指定SNAPSHOT版本也会失败,最初的&#34;无法找到工件&#34; -error,就像&#34; myGroupId:myParentArtifactId& #34;上方。

在浏览我看到Maven正在使用的存储库时,我可以看到SNAPSHOT版本。问题是为什么它找不到那里的快照?

1 个答案:

答案 0 :(得分:2)

在制定这个问题时,我实际上找到了答案:

我在我的settings.xml中添加了一个构建配置文件,用于定义查找快照的位置:

<profiles>
  <profile>
    <id>development-build</id>
    <activation>
      <activeByDefault>true</activeByDefault>
    </activation>      
    <repositories>
      <repository>
        <id>snaps</id>
        <url>http://repoHost:8081/nexus/content/repositories/my-snapshots</url>
        <snapshots>
          <enabled>true</enabled>
          <checksumPolicy>warn</checksumPolicy>
          <updatePolicy>always</updatePolicy>
        </snapshots>
      </repository>
    </repositories>
  </profile>
</profiles>

现在一切都按预期工作了。

&#34;橡胶回避&#34;太棒了! : - )