I have created a multi-module maven project and I want to have two profiles, which I've declared as below.
<profiles>
<profile>
<id>bootstrap-server</id>
<modules>
<module>./bootstrapserver</module>
</modules>
</profile>
<profile>
<id>file-search</id>
<modules>
<module>./filesearch</module>
<module>./webservice</module>
</modules>
</profile>
</profiles>
When I choose, for an example, file-search profile, IntelliJ builds the profile fine (Using integrated maven panel in IntelliJ) and it builds only the two modules I've specified, which is the required behaviour. It works well for the other profile as well.
However, when I choose one profile, the directories of the modules in other profiles remain in the project structure window, as displayed below.
The image above shows how IntelliJ shows the project structure when I activate file-search profile.
Can I configure IntelliJ to remove the modules displayed in the Project window which are not used in one profile? For an example, if I select file-search module, I want to remove bootstrapserver module from the Project panel since it's not being used when developing under file-search profile.
Thank you.
Related
I have a Java project build with Maven analyzed with SonarQube. Each project consists of a couple of Maven modules, let's say:
org.acme.module - API
org.acme.module.demo - a small demo application demonstrating the features of this module
org.acme.module.doc - documentation for developers
org.acme.module.it - integration tests
In an ideal world I'd want to analyze the code quality of all of these modules, but calculate the test coverage only for the API.
However I could not find a way to disable entire projects from the code coverage (sonar.coverage.exclusions only filters the class name, and some of these modules share a package with the API), so now I'm trying to disable these modules from Sonar.
I tried:
<properties>
<sonar.skippedModules>org.acme.module.demo,org.acme.module.doc,org.acme.module.it</sonar.skippedModules>
</properties>
Which works, but is a lot of work, since I have hundreds of these projects.
<properties>
<sonar.skip>true</sonar.skip>
</properties>
Works too, but I have to define it similarly for every single sub-module. Also, now Sonar won't analyze the files, which is bad for obvious reasons.
I'd rather have something like <excludedModules>*demo*,*doc*,*it*,<excludedModules> which I could define once in the parent pom.xml and use in all these modules.
This answer states:
You could also do this from the sonar admin page as documented in the Skipping Modules section here.
I was so happy for a moment until I realized the SonarQube documentation does not contain the "Skipping Modules" section anymore. Or maybe it was moved and I just can't find it.
How do I skip the code coverage analysis in multiple modules while still running other Sonar tests?
Or if that's not possible, how to skip these modules in Sonar in a generic way?
Login as administrator
Go to your projects, and you should see an Administration tab.
Then go to Analysis Scope, then in coverage exclusions add your exclusions:
src/main/java/org/acme/module/demo/**
In all the child/sub module pom you can add something like below to exclude all the files in that module only from coverage analysis. You still will get the rest of the SonarQube analysis for those modules.
<profiles>
<profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<sonar.coverage.exclusions>
**/*.*
</sonar.coverage.exclusions>
</properties>
</profile>
</profiles>
I have a Multi-Module Maven project. My parent POM has the following modules:
<module>common</module>
<module>ingest</module>
<module>package</module>
The package modules handles all aspects of building a deployable zip file using maven-antrun-plugin. The other two modules are where the core application code is located. Within the package I have various profiles holding the configuration settings for production, staging and development environments. Each profile looks like:
<profile>
<id>prod</id>
<properties>
<oozie.url>http://oozie-server:11000/oozie</oozie.url>
<stage.user>prod-stage</stage.user>
</properties>
</profile>
This works perfectly at the parent level, running:
mvn clean install -P prod
All the .properties file have the various properties expanded to be the ones in the Maven profile.
Within the ingest module, one class may rely upon a .properties file with the ingest module. The contents of this properties file will look something like:
stageUser=${stage.user}
When running tests for the ingest module, the properties are not expanded to be the properties from the build profile e.g. the property will still be stageUser=${stage.user} rather than stageUser=prod-stage. This causes the test to fail.
The only workaround I have is to add in the required profiles and properties to get the test to pass into the ingest POM. This means I have these properties in two locations both the package and ingest modules. Is there a better solution to this?
The inheritance of properties from the parent should work. Make sure you have the parent declaration in the child modules:
<parent>
<artifactId>parent</artifactId>
<groupId>parentGroupId</groupId>
<version>version</version>
</parent>
I use this to build my spring mvc app:
mvn clean package
I use the maven war plugin to create a war file, but the problem I am facing is that in my resources folder I have my development versions of my .properties files for log4j etc.
When I push to production, and run:
java -jar ...
It explodeds the war file, and then at that point I can modify the .properties files with my production settings, but I obviously want to do this during my maven build for production.
Is there a way I can tell maven that this is a production build, so get these files from somewhere else? And during development, keep doing what it is doing now?
User maven profiles. Maven profiles help you in specifying different properties for different profiles. So you can have two profiles - development and production.
Something like this -
<profiles>
<profile>
<id>development</id>
<!-- we'll properties here... -->
</profile>
<profile>
<id>production</id>
<!-- ...and here -->
</profile>
</profiles>
Like this example -
<profile>
<id>development</id>
<properties>
<db.driverClass>oracle.jdbc.driver.OracleDriver</db.driverClass>
<db.connectionURL>jdbc:oracle:thin:#127.0.0.1:1521:XE</db.connectionURL>
</properties>
</profile>
<profile>
<id>production</id>
<properties>
<db.driverClass>oracle.jdbc.driver.OracleDriver</db.driverClass>
<db.connectionURL>jdbc:oracle:thin:#134.0.0.1:3124:XE</db.connectionURL>
</properties>
</profile>
There are a couple of options here. The first (as others have mentioned as well) is to use maven profiles. Instead of having multiple version of your properties files, you would have something like:
mypropsfile.properties
-----------------------
prop1=${prop1.val}
prop2=${prop2.val}
Then in your profiles, you can define values for those properties (make sure you have resource filtering enabled for this to work. see an example http://www.manydesigns.com/en/portofino/portofino3/tutorials/using-maven-profiles-and-resource-filtering).
You can also have your properties file have production values in it but with the ability to override those files in development. Spring profiles are helpful for this. For example, in development mode you can look for a properties file named <user-home>/mypropertiesoverride.properties, which could be used to override any of the production value properties with development specific ones.
I prefer the second method here where you have a default properties file and then you can just override select properties.
I have a lot of maven projects. I have two different global settings.xml for them which I need to merge. Both of them describes their repositories inside the profiles. I merged the two settings.xml by the mirrors and profiles tags.
One of the profiles is activated by the activeProfile tag in settings.xml file.
I want to ask you, how I can change the active profile in the different projects? Can I select it in the project pom.xml file?
Thanks,
Br, Stristi
This document describes how profiles can be activated: Introduction to Build Profiles.
You could activate profiles via environment variables, but if you have many projects, and want to apply profiles per-project basis, then it's a fault solution to change environment variable before each separate project build execution. If you are working with IDE, you can configure launch configuration to set the property for each project, and you have to configure the correct mvn run command within a continuous integration for each project. However, that would make it impossible to build an aggregated build consisting of different projects that should be activated by different profiles.
A possible workaround (which doesn't seem to be elegant, but I'm pretty sure it will work) is activating profiles based on file presence, and managing such 'marker files' for different projects to activate the required one. For example:
<profiles>
<profile>
<activation>
<file>
<exists>.profile-A</exists>
</file>
</activation>
...
</profile>
</profiles>
Expected behavior: This profile gets activated if file with a name '.profile-A' exists in a root folder of a project.
However, at this point one more interesting question arises: what would be the behavior in case of aggregated build?
It sounds you need to use a Repository Manager (Archiva, Artifactory, Nexus alphabetical order) to have a single configuration in your settings.xml file. This will solve the issue of making your build files environment depend.
I prefer this way in my projects:
<profile>
<id>dev</id>
<activation>
<property>
<name>env</name>
<value>dev</value>
</property>
</activation>
...
</profile>
Then you can activate it this way:
mvn your_goal -Denv=dev
Regards,
Boskop
you can simple add the activeByDefault tag to your maven profile:
<profiles>
<profile>
<id>your-profile</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
</profiles>
I have following pom.xml
<project>
<properties>
<buildNumber>dev</buildNumber>
</properties>
<build>
<finalName>${project.artifactId}-${project.version}-${buildNumber}</finalName>
</build>
</project>
This works fine on development machine. If I run mvn package I've got project-1.1-dev.war artifact. If I run mvn package -DbuildNumber=121 I've got package-1.1-121.war.
But out CI server (TeamCity) always got project-1.1-dev.war despite the fact that buildNumber property passed to maven (if I remove default property definition from pom.xml, maven builds artifact with correct filename).
It seems that system property resolve priority is somehow depends on platform (maven version is equals on both developer machine and TC - 2.2.1)?
That's a bit strange... Maybe you can't force the parameter given in the command line to have a highest priority than the one defined in the <properties> tag.
An idea is to use a profile that define the property buildNumber:
<profiles>
<profile>
<id>dev-property</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<buildNumber>dev</buildNumber>
</properties>
</profile>
</profiles>
So by default, buildNumber will be equals to dev value. Now, in your TeamCity command line, disable this profile with the command mvn ... -P !dev-property (the ! before a profile id indicates that the profile must be disabled).
The answer to your question lies in another question here on SO: Maven property overloading
In short, you need to pass -DbuildNumber=121 on the maven command line (on the "3 build step: maven" page), because setting system property "buildNumber" on the "6 properties and variables" page does not override the maven property.
Are you familiar with the concept of SNAPSHOT versions? Sounds like what you are trying to do, and is supported out of the box by Maven. Looks like you want to build major-minor-incremental or major-minor-dev, if you can live with major-minor-incremental-SNAPSHOT instead it should do what you want.