我正在尝试使用 Maven 依赖插件来获取特定版本范围内的工件。我需要在命令行(或在脚本中)执行此操作
这是我尝试过的:
mvn dependency:get -Dartifact="junit:junit:[4.0,4.11)"
但是,这个范围显然没有被认可。 Maven 尝试下载文字版本为 [4.0.0,4.11.0).
的工件,但失败了我想我使用了错误的语法和/或没有正确转义。
如何让maven获取符合指定版本范围的最高版本的工件?
错误信息:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.8:get (default-cli) on project standalone-pom: Couldn't download artifact: Missing:
[ERROR] ----------
[ERROR] 1) junit:junit:jar:[4.0,4.11)
此目标不支持版本范围:
https://issues.apache.org/jira/browse/MDEP-88
我得到:
Failed to retrieve POM for junit:junit:jar:[4.0,4.11): Could not transfer artifact junit:junit:pom:[4.0,4.11) from/to central (https://repo.maven.apache.org/maven2): Illegal character in path at index 49: https://repo.maven.apache.org/maven2/junit/junit/[4.0,4.11)/junit-[4.0,4.11).pom
所以范围没有被解析。
不确定有什么替代方案可以完成完全相同的事情:/
版本插件允许解析范围http://www.mojohaus.org/versions-maven-plugin/resolve-ranges-mojo.html但只能在 pom.xml 中 - 需要创建一个假 pom。 xml - 使用此插件来解析版本,然后从创建的 pom 中获取它 - 希望有更好的方法...
为了解决我遇到的类似情况
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.group.name</groupId>
<artifactId>name-maven-plugin</artifactId>
<version>[x,]</version> <!-- use any range -->
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>com.group.name</groupId>
<artifactId>name-maven-plugin</artifactId>
<!-- specify no version -->
<configuration>
<!-- any config -->
</configuration>
</plugin>
....
上述方法有效,但是您会收到有关插件中缺少版本的警告,因此在未来的 Maven 版本中这可能会出错 - 根据警告
这是使用 maven-assemble-plugin 的解决方法。它将版本范围的 zip 依赖项的内容解压到目录
super/parent
。
pom.xml:
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>my-stuff</artifactId>
<type>zip</type>
<version>(,2)</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>...</id>
<phase>...</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<attach>false</attach>
<appendAssemblyId>false</appendAssemblyId>
<finalName>parent</finalName>
<formats>
<format>dir</format>
</formats>
<outputDirectory>super</outputDirectory>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
程序集.xml:
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.2.0
https://maven.apache.org/xsd/assembly-2.2.0.xsd">
<id>...</id>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<includes>
<include>com.example:my-stuff:zip</include>
</includes>
<unpack>true</unpack>
<useProjectArtifact>false</useProjectArtifact>
<useTransitiveDependencies>false</useTransitiveDependencies>
</dependencySet>
</dependencySets>
</assembly>