Question

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.

Was it helpful?

Solution

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

OTHER TIPS

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.

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

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

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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top