【发布时间】:2018-02-25 16:05:25
【问题描述】:
我在表达这个问题时遇到了一些麻烦,所以我会尽力抽象出尽可能多不相关的细节。如果需要更多详细信息,请询问。
我有一个包含 pom 的项目,该项目包含一个依赖项,当用户在该 pom 上执行mvn clean install 时,该依赖项总是被下载并解压缩到一个目录中。但是,当用户传入 mvn clean install -Dcontent=false 之类的属性但在 pom.xml 中执行其他所有操作时,我想放弃该依赖项的下载和解包。
由于缺乏更好的表达方式,我想知道如何在 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时才执行
【问题讨论】:
-
依赖项是可选的,如您提供的链接中所述的方式,或者您需要它...您可以举个例子吗?