How to skip install phase in Maven build if I already have this version installed in repo

55,152

Solution 1

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

Solution 2

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.

Solution 3

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

Solution 4

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

Solution 5

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>
Share:
55,152

Related videos on Youtube

ximage
Author by

ximage

Updated on July 09, 2022

Comments

  • ximage
    ximage almost 2 years

    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.

  • ximage
    ximage almost 13 years
    This is the best solution. But not all plugins have "skip".
  • Cemo
    Cemo about 12 years
    Does install plugin has a skip configuration?
  • Michał Kalinowski
    Michał Kalinowski about 12 years
    maven-install-plugin does not have skip configuration parameter. Provided solution basically doesn't work at all.
  • Brad Cupit
    Brad Cupit almost 10 years
    @MichalKalinowski It does as of version 2.4, see https://jira.codehaus.org/browse/MINSTALL-73
  • Doug
    Doug about 9 years
    This solution did not work for me. I also noticed that the maven settings.xml file had a warning that the <build> element is 'unrecognized'. I will offer my solution in an answer.
  • haui
    haui over 2 years
    I think this is not a solution to the general problem. First jar:jar will re-build the jar artifact what is not what you want. Other artifacts that may have been built during the packaging phase of the project are not built again and therefore not deployed. If you leave out the jar:jar part, no artifacts are known to the current build and you get the error "The packaging for this project did not assign a file to the build artifact."