mavenjenkinsmaven-3pom.xmlmaven-deploy-plugin

How to compile all modules but install/deploy only selected modules?


I've a typical multi-module maven project.

I would like to optimize the latter by deploying only the needed artifacts: that's 2 or 3 out of 100+ modules.

The build should still compile and test all modules but install/deploy only selected module artifacts to internal repo.

Question: Is there a way to do it?


Solution

  • In this case you could define in your aggregator/parent project (from which the main build should start) to skip the install and deploy executions via a property in order to disable them through all the modules by default. Then, in the few modules where this action should still be performed, you could override the specific property to enable them back again.

    Since the whole action is targeting a CI job, I would also suggest to wrap this behavior in a maven profile as following:

    In your aggregator/parent project you could define:

    <profiles>
        <profile>
            <id>ci-job</id>
            <properties>
                <disable.install.deploy>true</disable.install.deploy>
                <maven.install.skip>${disable.install.deploy}</maven.install.skip>
                <maven.deploy.skip>${disable.install.deploy}</maven.deploy.skip>
            </properties>
        </profile>
    </profiles>
    

    The snippet above is defining withinb the ci-job profile a new property, disable.install.deploy, set to true by default. Its value is then passed to the maven.install.skip propert of the maven-install-plugin:

    Set this to true to bypass artifact installation. Use this for artifacts that does not need to be installed in the local repository.

    And to the maven.deploy.skip property of the maven-deploy-plugin:

    Set this to 'true' to bypass artifact deploy

    As such, running the following:

    mvn clean install -Pci-job

    Would effectively skip install and deploy goals executions across the build (across all modules).

    That's half of the job however. In the few modules where you still want this action you could then define the following:

    <profiles>
        <profile>
            <id>ci-job</id>
            <properties>
                <disable.install.deploy>false</disable.install.deploy>
            </properties>
        </profile>
    </profiles>
    

    That is. Keeping the same profile name it will also be activated via the same global build invocation, setting however the key property to false and as such enabling again install and deploy for the modules where this profile would be added.