如果我已经在仓库中安装了这个版本,如何跳过 Maven 构建中的安装阶段

发布于 2024-09-07 19:10:42 字数 197 浏览 6 评论 0原文

我有一个由 3 个不同的库组成的项目。当我运行安装脚本时,它会从存储库中获取所有库并对其运行 mvn clean install 。但这个版本的库已经安装在仓库中。如果 pom.xml 中的版本与我本地存储库中的版本相同,有没有办法跳过安装阶段。

我知道我可以使用本地存储库并只需设置依赖项。但我的老板希望我们的项目只能使用公共回购来构建,而不需要任何我们的回购。

I have a project that consist of 3 different libraries. When I run install script it takes all libraries from repo and run mvn clean install on them. But this version of library already installed in repo. Is there a way to skip install phase if version in pom.xml equal version in my local repo.

I know that I can use local repo and just set dependencies. But my boss want that our project can build only with public repos and without any our repos.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

高速公鹿 2024-09-14 19:10:42

你可以像这样绕过

-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>

上周 Olivier Lamy 修补了这个 jira。

MINSTALL-73

You can bypass like this

-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>

Last week Olivier Lamy patched this jira.

MINSTALL-73

满意归宿 2024-09-14 19:10:42

大多数 Maven 插件可以通过指定类似的内容来跳过:

        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>X.Y</version>
          <configuration>
            <skip>true</skip>
          </configuration>
        </plugin>

您还可以设置构建配置文件来设置属性并使用它来确定值。例如,运行命令: mvn -Pexample 将选择“example”配置文件。然后,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 添加,安装插件的默认行为将是执行其默认目标,但如果选择了示例配置文件,则安装插件将跳过其目标。

Most maven plugins can be skipped by specifying something like:

        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>X.Y</version>
          <configuration>
            <skip>true</skip>
          </configuration>
        </plugin>

you can also set up build profiles to set properties and use that to determine the value. for example, running the command: mvn -Pexample would select the "example" profile. The POM would then contain:

...
  <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>
...

Using these POM additions, the default behavior for the install plugin will be to perform its default goal, but if the example profile is selected, then the install plugin will skip its goal.

┈┾☆殇 2024-09-14 19:10:42

根据我从其他答案中学到的知识,这对我来说是最干净的结果。

在我的超级 pom 中,我添加了一个pluginManagement/plugin,以在设置属性 deployOnly 时禁用默认安装和默认测试阶段。

            <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

Using what I learned from the other answers, this was the cleanest result for me.

In my super pom I added a pluginManagement/plugin to disable default-install and default-test phases when the property deployOnly is set.

            <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>

So on the command line, I can disable install and test phases by adding -DdeployOnly.

mvn clean install       #build and test everything
mvn deploy -DdeployOnly #just deploy it
み格子的夏天 2024-09-14 19:10:42

我知道我可以使用本地存储库并只需设置依赖项。但我的老板希望我们的项目只能使用公共存储库来构建,而无需任何我们的存储库。

你确定你正确理解了老板的意思吗?我将上述内容解释为“不要在本地存储库中安装第三方库,仅使用公共存储库中可用的库”。这与“不使用本地存储库”不同,后者基本上是不可能的,这不是 Maven 的工作方式。我想尝试澄清这一点。

除此之外,我没有得到一个非常令人困惑的问题(你在说什么存储库?安装脚本在做什么?为什么你在库上调用干净安装?等等)。

I know that I can use local repo and just set dependencies. But my boss want that our project can build only with public repos and without any our repos.

Are you sure you understood correctly what you boss meant? I interpret the above as "don't install third party libraries in your local repository, use only libraries available in public repositories". This is different from "don't use your local repository" which is basically impossible, that's just not how maven works. I'd try to clarify this point.

Apart from that, I don't get the question which is very confusing (what repo are you talking about? What is the install script doing? Why do you call clean install on libraries? etc).

浅笑依然 2024-09-14 19:10:42

从未来扩展其他答案。

Maven 插件有惊人的高自由度,它们如何运行。如果他们愿意,他们可以忽略/覆盖典型的 pom.xml 设置。此外,true也只是一个约定,没有什么强制插件遵循它,除了大多数插件都是这样开发的。

我对最近问题的实验表明,@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>

Extending the other answers, from the future.

Maven plugins have a surprisingly high freedom, how do they run. If they want, they can ignore/override the typical pom.xml settings. Furthermore, also the <configuration><skip>true</skip></configuration> is only a convention, nothing obligates a plugin to follow it, except that most of them is developed so.

My experiments with the recent problem show, that both @Cemo's and @MiloshBoroyevich solution should be utilized, also the plugin requires both to really let us in peace. More concretely, the only working configuration by me was this:

<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>
爱给你人给你 2024-09-14 19:10:42

您的选择之一是将部署放入另一个模块。即,使用一个 pom.xml 构建工件并将其安装到本地存储库,并使用另一个 pom.xml 来部署它。这种分离在较大的项目中很常见,其中测试套件有时是一个单独的模块甚至是一个项目,打包分几个阶段进行,等等。

- pom.xml - myProject-root - type=pom
  - pom.xml - myProject-artifact - type=jar
  - pom.xml - myProject-deploy - type=pom, does the deployment, skips it's own `install` goal

One of your options is to put the deployment to another module. I.e. have one pom.xml build the artifact and install it to the local repo, and another pom.xml to deploy it. This separation is quite common in larger projects, where the testsuite is sometimes a separate module or even a project, the packaging happens in several stages, etc.

- pom.xml - myProject-root - type=pom
  - pom.xml - myProject-artifact - type=jar
  - pom.xml - myProject-deploy - type=pom, does the deployment, skips it's own `install` goal
听,心雨的声音 2024-09-14 19:10:42

以避免安装阶段

mvn verify deploy:deploy

to avoid install phase

mvn verify deploy:deploy
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文