Does Java – Maven dependency plugin use the same other types of artifact resolution as other mavens?

If I use the Maven dependency plugin, I cannot use the version range In addition, it seems that the version of a defined artifact has not been updated, although the newer version is in the remote repository

Why?

Use Maven dependency plugin some other mechanisms to resolve dependencies? If so, why?

Here is an example:

I have created a project. Org example:org. example. simple. Project1: jar and put it in the repository, using version 1.0 0-SNAPSHOT,1.0. 0,1.0. 1 and 1.1 0-SNAPSHOT

I have now configured the dependent plug-ins as follows:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <execution>
            <id>unpack-stuff<id>
            <phase>initialize</phase>
            <goals>
                <goal>unpack</goal>
            </goals>
            <configuration>
                <artifactItems>
                    <artifactItem>
                        <groupId>org.example</groupId>
                        <artifactId>org.example.simple.project1.</artifactId>
                        <version>[1.0,1.1)</version>
                        <type>jar</type>
                        <overWrite>true</overWrite>
                        <outputDirectory>target/stuff</outputDirectory>
                        <includes>**/*.*</includes>
                    </artifactItem>
                </artifactItems>
            </configuration>
        </execution>
    </executions>
</plugin>

If the solution of the dependency is the same as other dependencies, the version will decide (at least in my opinion) to be 1.0 one

Instead, I get the following exceptions:

[ERROR] Fatal error
[INFO] ------------------------------------------------------------------------
[INFO] version was null for org.example:org.example.simple.project1.
[INFO] ------------------------------------------------------------------------
[INFO] Trace
java.lang.NullPointerException: version was null for org.example:org.example.simple.project1.
at org.apache.maven.artifact.DefaultArtifact.getBaseVersion(DefaultArtifact.java:362)
at org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout.pathOf(DefaultRepositoryLayout.java:47)
at org.apache.maven.artifact.repository.DefaultArtifactRepository.pathOf(DefaultArtifactRepository.java:110)
at org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:125)
at org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:74)
at org.apache.maven.plugin.dependency.fromConfiguration.AbstractFromConfigurationMojo.getArtifact(AbstractFromConfigurationMojo.java:242)
at org.apache.maven.plugin.dependency.fromConfiguration.AbstractFromConfigurationMojo.getProcessedArtifactItems(AbstractFromConfigurationMojo.java:143)
at org.apache.maven.plugin.dependency.fromConfiguration.UnpackMojo.getProcessedArtifactItems(UnpackMojo.java:138)
at org.apache.maven.plugin.dependency.fromConfiguration.UnpackMojo.execute(UnpackMojo.java:88)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:453)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:559)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:500)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:479)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:331)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:292)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:142)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:336)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:129)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:301)
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.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4 seconds
[INFO] Finished at: Mon Aug 03 17:21:41 CEST 2009
[INFO] Final Memory: 13M/133M
[INFO] ------------------------------------------------------------------------

Solution

OK, this is the real answer (I wrote the dependency plug-in):

Decompression and replication targets must copy some core solution code Unfortunately, the solution code is not really a useful form Therefore, these goals cannot handle the version range and will not parse artifacts directly from the reactor (I frankly never implement them because it destroys a large number of existing use cases and the core solution code is bad)

A better approach is to use the XXX dependency form of these targets These goals require Maven to make decisions before being called, so it is 100% compatible You can use filters like groupid and artifactid filters to effectively get the required list of artifacts, and the end result will be the same

Replication and decompression are certainly more flexible, designed for a simpler use case used at the time Knowing what I know now, I may implement it more like the beginning of XXX dependency form

All this, in Maven 3, the solution code is finally completely decoupled... Dependent plug-ins drive most of the required use cases I will start using the new version of the plug-in to make full use of this feature as soon as possible, and it will require Maven 3, which will eventually reach the goal of 100%

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>