使用mvn install命令

时间:2016-03-08 06:06:36

标签: java maven maven-2 maven-3 maven-plugin

我使用的是MAVEN的最新版本。我必须使用MAVEN构建我想要的项目。 我的第一个项目是基于模块的项目,它有两个模块。该项目的父POM包括2个子POMS。我将通过命令提示符将版本作为变量传递,以使此构建独立于静态版本。

我的父POM 如下所示:

<modelVersion>4.0.0</modelVersion>
<groupId>A.B.C</groupId>
<artifactId>D</artifactId>
<version>${major.version}.${build.version}</version>
<packaging>pom</packaging>

<!-- Some further code-->

一个模块有POM,如:

<parent>
    <groupId>A.B.C</groupId>
    <artifactId>D</artifactId>
    <version>${major.version}.${build.version}</version>
</parent>

**<groupId>A.B.C</groupId> 
<artifactId>E</artifactId>**
<version>${major.version}.${build.version}</version>

<!-- Some further code-->

第二个模块的POM如下:

<parent>
    <groupId>A.B.C</groupId>
    <artifactId>F</artifactId>
    <version>${major.version}.${build.version}</version>
</parent>

**<groupId>A.B.C</groupId> 
<artifactId>G</artifactId>**
<version>${major.version}.${build.version}</version>

<!-- Some further code-->

我的第二个项目在其POM中使用上述依赖关系,如:

<modelVersion>4.0.0</modelVersion>
<groupId>A.B.C</groupId>
<artifactId>T</artifactId>
<version>0.0.1</version>

<packaging>jar</packaging>

<dependencies>

    <dependency>
        **<groupId>A.B.C</groupId> 
        <artifactId>E</artifactId>
        <version>LATEST</version>**
    </dependency>

    <dependency>
        **<groupId>A.B.C</groupId> 
        <artifactId>G</artifactId>
        <version>LATEST</version>**
    </dependency>

但是在使用 mvn clean install 时,它会给

带来错误

[错误]无法在项目T上执行目标:无法解析项目的依赖关系 引起:org.eclipse.aether.resolution.ArtifactResolutionException:无法转移工件ABC:D:pom:$ {major.version}。$ {build.version} from / to nexus-all-repos:IllegalArgumentException

但如果我使用命令 mvn版本:use-latest-versions ,它可以正常工作。我想使用 mvn install ,因为我只想为某些依赖项使用最新版本。

可能是什么问题?

添加完整的错误堆栈

   [ERROR] Failed to execute goal on project T: Could not resolve dependencies for project A.B.C:T:jar:5.6.0.15: Failed to collect dependencies at A.B.C:E:jar:LATEST: Failed to read artifact descriptor for A.B.C:E:jar:LATEST: Could not tran
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project T: Could not resolve dependencies for project A.B.C:T:jar:5.6.0.15: Failed to collect dependencies at A.B.C:E:jar:LATEST
        at org.apache.maven.lifecycle.internal.LifecycleDependencyResolver.getDependencies(LifecycleDependencyResolver.java:220)
        at org.apache.maven.lifecycle.internal.LifecycleDependencyResolver.resolveProjectDependencies(LifecycleDependencyResolver.java:127)
        at org.apache.maven.lifecycle.internal.MojoExecutor.ensureDependenciesAreResolved(MojoExecutor.java:257)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:200)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
        at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:120)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:347)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:154)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:582)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        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.apache.maven.project.DependencyResolutionException: Could not resolve dependencies for project A.B.C:T:jar:5.6.0.15: Failed to collect dependencies at A.B.C:E:jar:LATEST
        at org.apache.maven.project.DefaultProjectDependenciesResolver.resolve(DefaultProjectDependenciesResolver.java:167)
        at org.apache.maven.lifecycle.internal.LifecycleDependencyResolver.getDependencies(LifecycleDependencyResolver.java:195)
        ... 22 more
Caused by: org.eclipse.aether.collection.DependencyCollectionException: Failed to collect dependencies at A.B.C:E:jar:LATEST
        at org.eclipse.aether.internal.impl.DefaultDependencyCollector.collectDependencies(DefaultDependencyCollector.java:292)
        at org.eclipse.aether.internal.impl.DefaultRepositorySystem.collectDependencies(DefaultRepositorySystem.java:317)
        at org.apache.maven.project.DefaultProjectDependenciesResolver.resolve(DefaultProjectDependenciesResolver.java:159)
        ... 23 more
Caused by: org.eclipse.aether.resolution.ArtifactDescriptorException: Failed to read artifact descriptor for A.B.C:E:jar:LATEST
        at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.loadPom(DefaultArtifactDescriptorReader.java:384)
        at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.readArtifactDescriptor(DefaultArtifactDescriptorReader.java:231)
        at org.eclipse.aether.internal.impl.DefaultDependencyCollector.process(DefaultDependencyCollector.java:461)
        at org.eclipse.aether.internal.impl.DefaultDependencyCollector.collectDependencies(DefaultDependencyCollector.java:261)
        ... 25 more
Caused by: org.apache.maven.model.resolution.UnresolvableModelException: Could not transfer artifact A.B.C:D:pom:${major.version}.${build.version} from/to nexus-all-repos (http://eqmavenrepo.technologic.com/nexus/content/groups/allrepo/): IllegalArgumentException
        at org.apache.maven.repository.internal.DefaultModelResolver.resolveModel(DefaultModelResolver.java:170)
        at org.apache.maven.repository.internal.DefaultModelResolver.resolveModel(DefaultModelResolver.java:219)
        at org.apache.maven.model.building.DefaultModelBuilder.readParentExternally(DefaultModelBuilder.java:898)
        at org.apache.maven.model.building.DefaultModelBuilder.readParent(DefaultModelBuilder.java:750)
        at org.apache.maven.model.building.DefaultModelBuilder.build(DefaultModelBuilder.java:309)
        at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.loadPom(DefaultArtifactDescriptorReader.java:375)
        ... 28 more
Caused by: org.eclipse.aether.resolution.ArtifactResolutionException: Could not transfer artifact A.B.C:D:pom:${major.version}.${build.version} from/to nexus-all-repos (http://eqmavenrepo.technologic.com/nexus/content/groups/allrepo/): IllegalArgumentException
        at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:459)
        at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifacts(DefaultArtifactResolver.java:262)
        at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifact(DefaultArtifactResolver.java:239)
        at org.apache.maven.repository.internal.DefaultModelResolver.resolveModel(DefaultModelResolver.java:166)
        ... 33 more
Caused by: org.eclipse.aether.transfer.ArtifactTransferException: Could not transfer artifact A.B.C:D:pom:${major.version}.${build.version} from/to nexus-all-repos (http://eqmavenrepo.technologic.com/nexus/content/groups/allrepo/): IllegalArgumentException
        at org.eclipse.aether.connector.wagon.WagonRepositoryConnector$6.wrap(WagonRepositoryConnector.java:1016)
        at org.eclipse.aether.connector.wagon.WagonRepositoryConnector$6.wrap(WagonRepositoryConnector.java:1004)
        at org.eclipse.aether.connector.wagon.WagonRepositoryConnector$GetTask.run(WagonRepositoryConnector.java:725)
        at org.eclipse.aether.util.concurrency.RunnableErrorForwarder$1.run(RunnableErrorForwarder.java:67)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
        at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.IllegalArgumentException
        at java.net.URI.create(URI.java:842)
        at org.apache.maven.wagon.providers.http.httpclient.client.methods.HttpGet.<init>(HttpGet.java:69)
        at org.apache.maven.wagon.providers.http.AbstractHttpClientWagon.fillInputData(AbstractHttpClientWagon.java:841)
        at org.apache.maven.wagon.StreamWagon.getInputStream(StreamWagon.java:116)
        at org.apache.maven.wagon.StreamWagon.getIfNewer(StreamWagon.java:88)
        at org.apache.maven.wagon.StreamWagon.get(StreamWagon.java:61)
        at org.eclipse.aether.connector.wagon.WagonRepositoryConnector$GetTask.run(WagonRepositoryConnector.java:660)
        ... 4 more
Caused by: java.net.URISyntaxException: Illegal character in path at index 119: http://eqmavenrepo.technologic.com/nexus/content/groups/allrepo/A/B/C/D/${major.version}.${build.version}/D-${major.version}.${build.version}.pom
        at java.net.URI$Parser.fail(URI.java:2809)
        at java.net.URI$Parser.checkChars(URI.java:2982)
        at java.net.URI$Parser.parseHierarchical(URI.java:3066)
        at java.net.URI$Parser.parse(URI.java:3014)
        at java.net.URI.<init>(URI.java:578)
        at java.net.URI.create(URI.java:840)
        ... 10 more
[ERROR]
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[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/DependencyResolutionException

删除非法字符后仍然出现错误

2 个答案:

答案 0 :(得分:1)

这不是Maven的工作方式。不要将POM看作仅仅是构建脚本,而是将更多作为交付单与您的工件一起发送,以解释它与世界其他地方的连接,例如:在依赖关系和如何 构建(注意过去时),而不是如何构建它,如Ant。

问题是如果 Maven允许你参数化${major.version}.${build.version}并将它们用作坐标,当它安装/部署时可能能够做到正确的事情并将您的工件部署到http://.../E/X.Y/E-X.Y.pom(如果您使用mvn -Dmajor.version=X -Dbuild.version=Y ...)。

然后问题出现了。另一个用户可能会正确下载您的工件,但是当Maven尝试解析POM时,它会遇到${major.version}.${build.version}并且不知道该怎么做,因为实际值是由您提供的当您部署并在此过程中丢失时。

这就是为什么Maven坐标需要修复而不是用属性外推的原因;它为您提供(也许更重要的是,任何其他依赖)控制和可追溯性。当然,其他非坐标属性可以参数化为您心脏的内容,它只是对此更敏感的坐标。

  

Maven坐标使用五个值,其中三个比另一个更常见:groupIdartifactIdversion。另外两个是packagingclassifier,但用于更奇特的用例。

如果您打算使用Maven,我建议您重新考虑您的构建方法。它有一个陡峭的学习曲线,但从顶部看起来很壮观。使用Maven释放工件最好通过例如Maven Release plugin

来完成

答案 1 :(得分:0)

我认为与回购路径中的错误符号有关的问题是在堆栈跟踪中。尝试检查与nexus repo相关的所有路径。

Caused by: java.net.URISyntaxException: Illegal character in path at index 119: ~^~content/groups/allrepo/~^~/E/${major.version}.${build.version}/E-${major.version}.${build.version}.pom