I have a maven project, but the father and son structure, I would like to perform mvn package in the parent structure at the same time want to specify the sub-project pom.xml file profile an id
You can define the sub-project module in your parent pom file profile as below:
<profiles>
<profile>
<id>all-deps</id>
<modules>
<module>sub-project</module>
</modules>
</profile>
</profiles>
Now you can use following maven commands to include the sub-project from parent
mvn package --activate-profiles all-deps
Related
I want to change the path of my target folder in maven. I am using C:/plugins but when I am updating my maven project I am getting An internal error occurred during: "Updating Maven Project". Path must include project and resource name: /ProjectName
<build>
<directory>/your/directory</directory>
</build>
Change in your pom.xml.
You should use profiles.
<profiles>
<profile>
<id>otherOutputDir</id>
<build>
<directory>yourDirectory</directory>
</build>
</profile>
</profiles>
i have a Maven multi project with several modules in the pom.xml.
But for the sonar-Scan i want to use other modules (includes and excludes)!
The property-file (sonar-project.properties) is not used in Maven-Projects, so the properties sonar.modules and xxx.sonar.projectBaseDir are not working.
How can i configure it with Maven?
You can use Maven profiles to include only specific modules: http://maven.apache.org/guides/introduction/introduction-to-profiles.html
Example:
<profiles>
<profile>
<id>all</id>
<modules>
<module>module-A</module>
<module>module-B</module>
<module>module-C</module>
</modules>
</profile>
<profile>
<id>sonar</id>
<modules>
<module>module-A</module>
<module>module-C</module>
<module>module-D</module>
</modules>
</profile>
</profiles>
Execute mvn -Psonar clean package sonar:sonar
I use a multi module build file to trigger the build of a rather complex java project. Now I want to create the eclipse project files - but not for all modules. Is it possible to define on a pom, that it shall ignore the eclipse:eclipse goal?
The modules definition of the multi-module pom, that I call with mvn eclipse:eclipse looks like that:
<modules>
<module>../project1/generate/pom.xml</module>
<module>../project1/pom.xml</module>
<module>../project2/generate/pom.xml</module>
<module>../project2/pom.xml</module>
<!-- and many more projects with or without generate sub modules -->
</modules>
Of course the pom is not only needed for creating eclipse projects so I can't just remove the modules that cause trouble with that goal.
The reason for asking: eclipse:eclipse executed on the generate modules will change some attributes in manifest files with the effect that the next build breaks. And I'm tired of correcting them manually all the time ;)
You can use Maven Profiles for this.
Remove your defined modules and add something like this:
<profiles>
<profile>
<id>full</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<modules>
<module>../project1/generate/pom.xml</module>
<module>../project1/pom.xml</module>
<module>../project2/generate/pom.xml</module>
<module>../project2/pom.xml</module>
</modules>
</profile>
<profile>
<id>eclipse</id>
<modules>
<module>../project1/pom.xml</module>
<module>../project2/pom.xml</module>
</modules>
</profile>
</profiles>
Then when you want to generate eclipse settings:
mvn -Peclipse eclipse:eclipse
You can use Maven Advanced Reactor Options (since Maven 2.1):
For instance, to target only project1 and project2:
mvn --projects project1, project2 eclipse:eclipse
to target project1 and all its dependencies:
mvn --projects project1 --also-make eclipse:eclipse
This provides a standardised way for reactoring multi-mudule projects and does not requires modification in pom.xml.
I have a Maven POM that aggregates several modules.
<project [stuff]>
<modelVersion>4.0.0</modelVersion>
<groupId>com.fuhu.osg</groupId>
<artifactId>UserManagement</artifactId>
<packaging>pom</packaging>
<version>1.0</version>
<name>UserManagement</name>
<modules>
<module>core</module>
<module>war</module>
<module>ejbs</module>
<module>ear</module>
</modules>
</project>
I want to execute a goal that doesn't apply to the modules against the top-level POM. Something like mvn db-migrate:create. As is, it seems like this attempts to run said command against the sub-projects, which is correct for every OTHER goal, but not for this one.
Is there a way to make a Maven POM that is both an Aggregate for some goals and an ordinary project for others?
You might be helped by Maven build profiles. It's easy to configure one submodule to be invoked when using a certain profile.
http://maven.apache.org/guides/introduction/introduction-to-profiles.html
...
<profiles>
<profile>
<id>db</id>
<modules>
<module>core</module>
</modules>
</profile>
<profile>
<id>all</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<modules>
<module>core</module>
<module>war</module>
<module>ejbs</module>
<module>ear</module>
</modules>
</profile>
...
Start your db task with the db profile with something like:
$ mvn -Pdb db-migrate:create
Auto activation of profiles is possible using system environment etc. Sadly I can't find a maven property for the command line goal, which would enable auto activation of a profile when that specific goal is run.
I have a multi module maven project, which builds successfully, I'd like to build just one of the modules I have. How would I do that with profiles ? I could do it from console in two ways, one way is go to the child module and mvn package or I could use reactor to build just one module.
Can I do the same thing with profiles? By modifying POM? Thank you
EDIT
If is impossible from POM, can I do it from settings.xml ?
To implement this with profiles, you could use two profiles, one <activeByDefault> with all modules and another one with the wanted module only. Something like this:
<profiles>
<profile>
<id>all</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<modules>
<module>module-1</module>
...
<module>module-n</module>
</modules>
</profile>
<profile>
<id>module-2</id>
<modules>
<module>module-2</module>
</modules>
</profile>
<profiles>
And then call it like this:
mvn -Pmodule-2 package
Two things to note here:
You need to move the <modules> from the POM in a "default" profile (because <modules> from a profile are only additive, they do not hide the modules declared in the POM).
By marking it as <activeByDefault>, the "default" profile will be picked if nothing else is active but deactivated if something else is.
One could even parametrize the name of the module and pass it as property:
<profiles>
...
<profile>
<id>module-x</id>
<activation>
<property>
<name>module-name</name>
</property>
</activation>
<modules>
<module>${module-name}</module>
</modules>
</profile>
<profiles>
And invoke maven like this:
mvn -Dmodule-name=module-2 package
But this is a poor implementation IMHO, I prefer the -pl "advanced" reactor options (less xml, much more power and flexibility):
mvn -pl module-2 package
To overcome additivity nature of maven default <modules> working with <profiles>, you can use reactor with particular profile, e.g.:
mvn -pl module-2 -Pprofile-name package
This will package module-2 defined in profile-name and not in default profile.