4

I've a typical multi-module maven project.

  • There's a Jenkins job which builds and deploys all snapshots to the internal repository.
  • There's another Jenkins build which checks out code, updates all pom versions, and builds & deploys versioned artifacts.

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?

A_Di-Matteo
  • 26,902
  • 7
  • 94
  • 128
phanin
  • 5,327
  • 5
  • 32
  • 50

1 Answers1

6

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.

A_Di-Matteo
  • 26,902
  • 7
  • 94
  • 128
  • excellent, do you think `disable.install.deploy` could be a top level in which case I just need to redefine the property instead of the entire profile. I will try it myself anyways, just wanted to ask. – phanin May 05 '16 at 22:07
  • @phani you can define them as top-level, but it really depends whether you want to keep this configuration as defaul behavior or only as CI behavior, that's why I suggested to wrap (and isolate) the behavior in a profile. Up to you, obviously, how to then apply to your specific needs. Hope it helped – A_Di-Matteo May 10 '16 at 07:33
  • @phani did you solve this issue eventually? you didn't accept the answer nor share additional feedbacks. just checking :) – A_Di-Matteo Jun 09 '16 at 07:02
  • Sorry, I tested it to some extent and it got sidelined. Will soon share details. Thanks. – phanin Jun 09 '16 at 15:52