Rocky
Rocky

Reputation: 401

maven install lifecycle does not execute validate

I have to install a custom jar during build time, I don't have choice to run deploy file to upload custom jar to central nexus.

The custom jar, does not have any dependencies and is pretty simple Here is my pom file.

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
<executions>
    <execution>
        <id>install-asjava</id>
        <phase>validate</phase>
        <goals>
            <goal>install-file</goal>
        </goals>
        <configuration>
            <groupId>com.ibm</groupId>
            <artifactId>customjar1</artifactId>
            <version>1.0.0</version>
            <packaging>jar</packaging>
            <file>${basedir}/lib/customjar1.jar</file>
            <generatePom>true</generatePom>
        </configuration>
    </execution>
    <execution>
        <id>install-unijdbc</id>
        <phase>validate</phase>
        <goals>
            <goal>install-file</goal>
        </goals>
        <configuration>
            <groupId>com.ibm</groupId>
            <artifactId>customjar2</artifactId>
            <version>1.0.0</version>
            <packaging>jar</packaging>
            <file>${basedir}/lib/customjar2.jar</file>
            <generatePom>true</generatePom>
        </configuration>
    </execution>
</executions>
</plugin>

When I run maven validate, these custom jars get installed locally fine, but I want to run install-plugin during install time, I changed phase to install and it fails with error

[WARNING] The POM for com.ibm:customjar1:jar:1.0.0 is missing, no dependency information available
[WARNING] The POM for com.ibm:customjar2:jar:1.0.0 is missing, no dependency information available

I have to always explicitly run validate before running install, I want to get around this problem. Maven documentation says all the phases before a particular gets executed as part of execution cycle, but some how it is not working for me.

Even, this article says the same thing, you need to run validate explicitly to make sure maven install work fine.

Upvotes: 2

Views: 2737

Answers (1)

DB5
DB5

Reputation: 13978

This is a bug (or not dependening on your view) that has been closed as Won't Fix: https://issues.apache.org/jira/browse/MNG-5082

Here is the relevant comment from the bug:

all dependencies which are not part of the reactor should be available at startup of the build, which is required to make a valid buildPlan. So even though this used to work with Maven2, I think the approach of Maven3 is better, since Maven can't detect which plugins will effect the buildPlan at startup. I'd like to close this as Won't Fix. Doing an install-file during validate means that it'll be execute during every build, installing the same file over and over again. That's also a sign that this approach can't be valid.

What you could try is to turn your project into a multi-module project. The first module simply includes the maven-install-plugin configuration - so all that module does is upload your two custom jars to the local repository. Your 2nd module would then depend on this first module. By the time the 2nd module builds the 1st module will have uploaded the custom jars meaning they should be available.

Upvotes: 5

Related Questions