我在解决这个问题时遇到了一些麻烦,所以我会尽我所能去尽可能多地抽象出不相关的细节。如果需要更多细节,请询问。在maven中设置属性标志时如何跳过下载依赖关系
我有一个包含pom的项目,其中包含一个依赖关系,当用户在该pom上执行mvn clean install
时,该依赖关系总是会下载并解压缩到目录中。不过,我希望在用户通过诸如mvn clean install -Dcontent=false
之类的属性时下载并解压该依赖关系,但在该pom中执行其他所有操作。
对于缺乏更好的方式来说这个,我想知道如何在maven中使可选的依赖项?在这里描述的意义上不是可选的: http://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html
但在构建时可选,如上所述。
编辑:
生成步骤
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>unpack</id>
<phase>compile</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.company.random</groupId>
<artifactId>content</artifactId>
<version>${contentVersion}</version>
<type>zip</type>
<outputDirectory>contentdir/target</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugins>
</build>
@Mikita目前该会一直执行,我怎么能做出这样执行,只有当-Dcontent=true
一个依赖或者是可选的,就像你给的链接中描述的那样,或者你需要它......你能举个例子吗? – khmarbaise