Skip compilation in gmavenplus plugin - maven

I currently work in big project built by Maven which has many integration tests modules which are marked as main (not testing) sources.
I am trying to create a profile which would skip compilation of these modules.
I expected gmaven plugin to allow "skip" configuration parameter but this is not the case.
Is there any way to skip module processing without pointing gmaven plugin to non-existent directory and without copy-paste of all modules except integration tests to a separate profile?

You can put the integration test modules in a separate profile of the parent pom where you list the modules. The profile should be active unless you disable it by setting a property when running the Maven build (-DskipIntegrationTestModules). (Don't use activeByDefault.)
<modules>
<module>my-project</module>
</modules>
<profiles>
<profile>
<id>build-integration-tests</id>
<activation>
<property>
<name>!skipIntegrationTestModules</name>
</property>
</activation>
<modules>
<module>my-project-integration-test</module>
</modules>
</profile>
</profiles>
You can find more details in the Maven Introduction to Build Profiles.
You should also know that it can be dangerous to have modules in build profiles because they could be accidentally left out when doing release builds. I think it should be OK in this case because the profile has to be deactivated explicitly.

Related

Maven skip module when we package / test

I have multiple modules in my maven project.
<modules>
<module>module-1</module>
<module>module-2</module>
<module>module-3</module>
</modules>
I would like to skip 1 module , say module-3 when i do package or test etc. This below profile option does not seem to work.
<profiles>
<profile>
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<modules>
<module>module-1</module>
<module>module-2</module>
</modules>
</profile>
</profiles>
How to make this work or are there any alternatives?
After reading your comment, let me suggest the following:
module-3 is a module with integration tests. Its ok to compile it with other modules, it will be pretty fast and probably you'll want it anyway, otherwise it will eventually stop to compile. In addition, I don't think you should "play" with module structure like this, because the IDE should open all the modules (probably you open this "main" pom.xml)
Having said that you will probably want to run the tests only with some kind of flag. In this case you can define a profile for running integration tests instead of running the module.
In maven integration tests are usually managed by failsafe-plugin. So you can configure this plugin so that it will be actually executed only upon some property. It can be done with maven profiles.

How will you configure your pom.xml, so that another application bundle will not build again every time you run maven on your application?

In your application, you have to use another application bundle how will you configure your pom.xml, so that another application bundle will not build again every time you run maven on your application?
I assume you have a second maven dependency that gets build everytime you build your application. You ll need to modularize your parent POM and use separate profiles for partial build and full builds.
For example on your parent pom, modules section, include only your application core like this:
<modules>
<module>core</module>
</modules>
Under profiles, have separate profiles for application build and full build
<profiles>
<profile>
<id>autoInstallPackage</id>
<modules>
<module>ui.apps</module>
<module>ui.content</module>
</modules>....
<profile>
<profile>
<id>autoInstallWithSecondApplication</id>
<modules>
<module>secondapplication</module>
<module>ui.apps</module>
<module>ui.content</module>
</modules>....
<profile>
When you run mvn clean install -PautoInstallPackage, it will build core, ui.apps, ui.content. When you run mvn clean install -PautoInstallWithSecondApplication, it will build core and the dependency project, and then bundles up the deployment package.
You can easily exclude a sub-module as well, by using -pl '!moduleToExclude', this way, for example if you already have the code installed on AEM, you do not need to build it every time.

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

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

always download sources (and javadocs) from maven ant task

I am trying to get this ant-based project's init target to download all the sources and javadocs.
I added the following to my ~/.m2/settings.xml (as per Maven – Always download sources and javadocs) but it doesn't force source downloads when used from ant:
<profiles>
<profile>
<id>downloadSources</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<downloadSources>true</downloadSources>
</properties>
</profile>
</profiles>
The only way I could get the sources to download was by hacking build.xml so that all <artifact:dependencies> elements include sourcesFilesetId="sources.dependency.fileset", but this is a pretty distasteful commit that is unlikely to be accepted by the maintainers. A better solution would exist with a property file definition, preferably in the user's settings (not something that mutates the project definition)
Is there a simpler way to ensure that all the sources (and potentially javadocs) are globally downloaded in maven ant tasks?

Maven modules - how to build only child projects that exist in my workspace?

In my parent pom file:
<modules>
<module>../project-snapshot-a</module>
<module>../project-snapshot-b</module>
<module>../project-snapshot-c</module>
</modules>
However, in my workspace I have only projects A, B.
Other people have in their workspace only projects B, C.
How do I specify in the parent pom that I want to build a child project only if it can be located in the local workspace; otherwise I want it the updated snapshot to be fetched from the remote repository.
???
Here is a better version of the accepted answer. You can use profiles, of course, but I don't think that every programmer should have a profile. It will result in a large POM, just because you're missing some modules. Instead, you can do this:
http://maven.40175.n5.nabble.com/Ignore-module-if-missing-td84118.html
<profile>
<id>module1-build</id>
<activation>
<file>
<exists>module1/pom.xml</exists>
</file>
</activation>
<modules>
<module>module1</modules>
</modules>
</profile>
I think it's cleaner and it speaks for itself.
However, please note that if some modules depends on previous modules, it will not be an easy job.
You can have the modules declared in profiles, and each developer can have their own profile. You can set an environment variable to hold the programmer's name, and have the profile activate based on that variable.

Resources