我有一个由3个不同的库组成的项目。当我运行安装脚本时,它从repo获取所有库并在它们上运行mvn clean install。但是这个版本的库已经安装在repo中。如果我的本地存储库中的pom.xml中的版本相同,是否有一种方法可以跳过安装阶段。
我知道我可以使用本地repo并设置依赖项。但是我的老板希望我们的项目只能通过公共回购和没有我们的回购来建立。
你可以这样绕过
-Dmaven.install.skip=true
<profiles>
<profile>
<id>skipInstall</id>
<activation>
<property>
<name>maven.install.skip</name>
<value>true</value>
</property>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<executions>
<execution>
<id>default-install</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
上周奥利维尔拉米修补了这个jira。
通过指定以下内容可以跳过大多数maven插件:
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>X.Y</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
您还可以设置构建配置文件以设置属性并使用它来确定值。例如,运行命令:mvn -Pexample将选择“示例”配置文件。那么POM将包含:
...
<properties>
<skip.install>false</skip.install>
...
</properties>
...
<profile>
<id>example</id>
<properties>
<skip.install>false</skip.install>
</properties>
</profile>
...
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>X.Y</version>
<configuration>
<skip>${skip.install}</skip>
</configuration>
</plugin>
...
使用这些POM添加,安装插件的默认行为将是执行其默认目标,但如果选择了示例配置文件,则安装插件将跳过其目标。
使用我从其他答案中学到的东西,这对我来说是最干净的结果。
在我的超级pom中,我添加了一个pluginManagement / plugin,用于在设置属性deployOnly
时禁用default-install和default-test阶段。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
<executions>
<execution>
<id>default-install</id>
<configuration>
<skip>${deployOnly}</skip>
</configuration>
</execution>
<execution>
<id>default-test</id>
<configuration>
<skip>${deployOnly}</skip>
</configuration>
</execution>
</executions>
</plugin>
所以在命令行上,我可以通过添加-DdeployOnly
来禁用安装和测试阶段。
mvn clean install #build and test everything
mvn deploy -DdeployOnly #just deploy it
我知道我可以使用本地repo并设置依赖项。但是我的老板希望我们的项目只能通过公共回购和没有我们的回购来建立。
你确定你理解你老板的意思吗?我将上述解释为“不要在本地存储库中安装第三方库,只使用公共存储库中可用的库”。这与“不使用您的本地存储库”不同,这基本上是不可能的,这不是maven的工作原理。我试着澄清这一点。
除此之外,我没有得到一个非常令人困惑的问题(你在说什么回购?安装脚本在做什么?为什么要在库上调用干净安装?等等)。
从未来扩展其他答案。
Maven插件具有惊人的高自由度,它们如何运行。如果需要,他们可以忽略/覆盖典型的pom.xml设置。此外,<configuration><skip>true</skip></configuration>
也只是一个惯例,没有任何义务插件遵循它,除了大多数是这样开发。
我对最近问题的实验表明,应该利用@ Cemo和@MiloshBoroyevich解决方案,插件也需要真正让我们平静下来。更具体地说,我唯一的工作配置是这样的:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
<executions>
<execution>
<id>default-install</id>
<phase>none</phase>
</execution>
</executions>
<configuration>
<skip>true</skip>
</configuration>
</plugin>