I want to put the hibernate3-maven-plugin in my parent pom and have execution skipped in child modules if a given file does not exist in that module.
Is there any way to do this?
Up to now, I have had to do this:
<plugin>
...
<configuration>
<skip>true</skip>
<propertyfile>target/test-classes/jdbc.properties</propertyfile>
</configuration>
</plugin>
In the parent POM, and:
<plugin>
...
<configuration>
<skip>${maven.test.skip}</skip>
</configuration>
</plugin>
In all child POMs where I want it to execute. I.E Those actually having a jdbc.properties file.
You may be able to do this with profiles, but I suppose you'd probably not want to run it in the parent project, which may be problematic.
Here are some links on profiles:
http://maven.apache.org/guides/introduction/introduction-to-profiles.html
http://www.sonatype.com/books/mvnref-book/reference/profiles.html
http://mindthegab.com/2008/12/02/howto-give-your-multimodule-maven-build-subprojectenvironment-specific-behavior/
This question, had a similar issue and was not able to solve it with profiles:
activate-different-maven-profiles-depending-on-current-module
I'm not 100% on the logistics but you could possibly use the maven exec plugin in combination with a shell script. The shell script would check for the presence of the file and then invoke the mvn plugin using the maven pom directory - which can be obtained and passed to the shell script via the Maven environment variables.
Related
I got a liferay-portlet-project with a sample application/portlet that I want to become an archetype. Inside the project there is a folder containing two *.launch files to redeploy the webapp. Both have the following line which I have trouble with:
<stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY" value="${workspace_loc:/rawportlet}"/>
where "rawportlet" is the project's name. If I change it manually to ${artifactId} this variable is not resolved when using the archetype to create a project. Resolving this variable during project-generation would be nice.
Is there a way to achieve this? Or a workaround? Thanks in advance for your help.
Workaround: write a maven goal that the user can run after using the archetype. So the steps would be (for example):
generate project from archetype
mvn archetype:generate -DarchetypeCatalog=local
do some post-generation cleanup (execute in project's base dir)
mvn antrun:run
So my code for this is in "pom.xml" in the archetype:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>default-cli</id>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<replace token= "rawportlet" value="${artifactId}" dir="runConfigs">
<include name="**/*.launch"/>
</replace>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
The "runConfigs" directory is where the *.launch files are stored.
Credits to:
Full search and replace of strings in source files when copying resources
Maven, configure specific goal
I have this same problem, and I used a different solution that works okay (but isn't perfect either).
Use value="${workspace_loc}/${artifactId}" in your launch config.
This will work as long as people do an archetype:gen at the workspace root. This works better for me than the selected answer because running that post processing requires another launch configuration (which somewhat defeats the whole purpose).
In our "big build" (40+ modules), we have several modules that contain only tests.
When I give -DskiptTests to mvn, the tests are not executed.
But they are compiled, which costs up to a minute of build time.
How can I selectively turn off such modules when the option skipTests is set?
You'd have to organize your root pom such that the test modules are activated via a profile, and instead of using -Dmaven.test.skip to turn use -P!testProfile to deactivate them and hence skipping them.
Another thought is that you could just do:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<skip>${maven.test.skip}</skip>
</configuration>
</plugin>
</plugins>
I haven't actually tried that... it should in theory work. I seem to remember that the <skip> configuration is on all plugins.
Just to clarify the Gareth David point:
When you run mvn ... -DskipTests, only the execution of tests is skipped. This is the same behavior if you run mvn ... -Dtest=notest
When you run mvn ... -Dmaven.skip.test=true, then both test execution and compilation are skipped.
So the second command is enough, without any modification of your pom.xml file.
(source)
How to remove generated build artifacts from Maven's target directory? Maven generates a jar or war file to target directory. I'd like to remove that file after maven has installed the jar/war file to local repository (that is, after maven has executed the 'install' goal). The remove could happen either at install goal or separate goal I execute manually.
Note, that I'd like leave other parts of target directory intact, for example target/site and target/surefire-reports.
Just use the clean plugin and run an execution after the install phase:
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>auto-clean</id>
<phase>install</phase>
<goals>
<goal>clean</goal>
</goals>
<configuration>
<filesets>
<fileset>
<directory>${project.build.outputDirectory}</directory>
<includes>
<include>**/*.jar</include>
</includes>
</fileset>
</filesets>
</configuration>
</execution>
</executions>
</plugin>
There is nothing built into Maven that can do this. You could use the antrun plugin to execute an Ant script after install that deletes the artifact, or use the exec plugin to use the command line to delete the artifact, or write your own plug-in.
I suggest there is little value, if any, in doing any of these things. Maven is designed to place intermediate and final artifacts in target to make follow-on builds more efficient. The reason that there is nothing available to do this already is an indicator that this is of little value. If it is of value to you, you have a few options.
I know I am a little bit late. But I guess the issue was, that a maven project archives the artifacts automatically. In my case, I disabled the automatic archiving and just archived the artifacts manually using the post build actions. This way, only the artifacts that I am interested in are archived. I am willing to leave the generated artifacts on disk until the next build runs.
Is there a way to trigger a maven install command from another maven install command?
In other words, I would like to be able to execute a maven install command on a maven project (in eclipse) and I want that this will automatically cause an install command on another maven project.
Is that possible?
The Maven way to "trigger" another build is to define a multi-module build. A parent pom project can specify modules, that will all be built using the standard lifecycle. So running mvn install on the parent would mean that each module is built in turn.
The parent is defined with pom packagin, and would have a modules declaration like this:
<modules>
<module>module-a</module>
<module>module-b</module>
</modules>
Alternatively it is possible to attach additional artifacts to a build so they are deployed alongside the primary artifacts (assuming they've already been packaged, you can use the build-helper-maven-plugin to attach an arbitrary file to your pom, so it will be deployed with the specified classifier. The following configuration will attach the specified file as my-artifact-1.0-extra.jar
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>/path/to/extra/file.jar</file>
<type>jar</type><!--or specify your required extension-->
<classifier>extra</classifier>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
As pointed out, the maven way to launch a goal (lets say mvn install) on a set of modules is to organize them as a multi-module project and to launch the goal on the parent pom. Behind the scene, Maven will use a "Maven reactor" for this work. The reactor will calculate the build order by doing a topological sort of the nodes of the directed graph constructed by the dependency relation between modules. This graph is constructed by looking at <modules> and <dependencies> tags in poms.
But launching maven from a parent is not the only option and maven offers more possibilities to play with the reactor (e.g. making a project and its dependencies or those that depend on it):
With maven 2.0.x you have to use the reactor plugin : http://maven.apache.org/plugins/maven-reactor-plugin/ (see Reactor: My New Favourite Maven Plugin too)
With maven 2.1+ you can use native command line options : http://www.sonatype.com/people/2009/03/maven-210-released/ (see the new build mode options -amd, -rf, -am, -pl)
Check it out, it might help you to achieve your goal.
If i define a plugin in the <build> tag and want to use this in my site command how do i do that? Do i have to define the plugin within <reporting> tag again?
And how about the configuration which i probably have done within the build tag and want to take place at the reporting tag as well? (i dont want to specifie for example a location of a configuration file twice just to use a plugin in 2 lifecycles)
As example: I define my checkstyle plugin in the build tag and configrue a custom location for the rules to be used. I do that because the rules are packed in a jar so i can define it as dependency. This would not be possible if i do it in the reporting tag. But i need to use this plugin in the reporting tag aswell so surfire can generate a report for checkstyle. So i have to define the plugin within the reporting tag aswell.
Maybe i'm doing something complete wrong here but i don't see how i can do it other then that. What i dont like is that i have 1 plugin twice in my pom (in the build tag and reporting tag).
I hope somebody can verify my solution is ok, or give me an advise how to do it better.
thx
kuku
A maven plugin is typically bound to execution in a given lifecycle phase when you define it. The plugin itself specifies which lifecycle phase this is, but you can change this if you have special needs.
If you have a multi-module build you can define a set of plugins with all parameters required in a common parent-pom. This will normally be executed for every sub-module in the build. If you do not want this to happen you can define it (in the parent pom) like this:
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
... More plugin cofniguration stuff ...
</plugin>
If you in one or more nested moudules want to enable this plugin you can just say:
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>false</skip>
</configuration>
... Maybe Configuration ....
</plugin>
In that specific module. You can choose if you want to reconfigure the default parameters which are inherited from the parent definition or not.
I think this is what you're looking for ?
In addition to KRosenvold's answer, you can also minimize configuration by declaring a plugin in the <pluginManagment> section, perhaps at your topmost pom in the inheritance chain, and then you can omit specifying the version of the plugin in all the other places you are declaring it's use.
Parent Pom:
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-1</version>
</plugin>
</plugins>
<pluginManagement>
Child Pom:
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
</plugin>
</plugins>