Is there a way to use the current date in the POM? Take a look at the buildnumber plugin. It can be used to generate a build date each time I do a build, as follows: org.codehaus.mojo maven-buildnumber-plugin 0.9.4 {0,date,yyyy-MM-dd HH:mm:ss} timestamp
false false
validate create
pom.xml or settings.xml? What is the best practice configuration usage for these files? The best practice guideline between settings.xml and pom.xml is that configurations in settings.xml must be specific to the current user and that pom.xml configurations are specific to the project. For example, in pom.xml would tell all users of the project to use the specified in the pom.xml. However, some users may prefer to use a mirror instead, so they'll put in their settings.xml so they can choose a faster repository server. so there you go: settings.xml -> user scope pom.xml -> project scope
How do I indicate array types in a MOJO configuration?
value1 value2
How should I point a path for maven 2 to use a certain version of JDK when I have different versions of JDK installed on my PC and my JAVA_HOME already set? If you don't want to change your system JAVA_HOME, set it in maven script instead. How do I setup the classpath of my antrun plugin to use the classpath from maven? The maven classpaths are available as ant references when running your ant script. The ant reference names and some examples can be found here: maven-antrun-plugin Is it possible to use HashMap as configurable parameter in a plugin? How do I configure that in pom.xml? Yes. Its possible to use a HashMap field as a parameter in your plugin. To use it, your pom configuration should look like this:
yourvalue .....
How do I filter which classes should be put inside the packaged jar? All compiled classes are always put into the packaged jar. However, you can configure the compiler plugin to exclude compiling some of the java sources using the compiler parameter excludes as follows:
How can I change the default location of the generated jar when I command "mvn package"? By default, the location of the generated jar is in ${project.build.directory} or in your target directory. We can change this by configuring the outputDirectory of maven-jar-plugin.
Add the exact versions of plugins into your pluginDepenencies (make use of the release plugin)
Make use of ibiblio for your libraries. This should always be the case for jars. (The group is working on stabilising metadata and techniques for locking it down even if it changes. An internal repository mirror that doesn't fetch updates (only new) is recommended for true reproducibility.)
Why there are no dependency properties in Maven 2? They were removed because they aren't reliable in a transitive environment. It implies that the dependency knows something about the environment of the dependee, which is back to front. In most cases, granted, the value for war bundle will be the same for a particular dependency - but that relies on the dependency specifying it. In the end, we give control to the actual POM doing the building, trying to use sensible defaults that minimise what needs to be specified, and allowing the use of artifact filters in the configuration of plugins.
What does aggregator mean in mojo? When a Mojo has a @aggregator expression, it means that It can only build the parent project of your multi-module-project, the one who has the packaging of pom. It can also give you values for the expression ${reactorProjects} where reactorProjects are the MavenProject references to the parent pom modules. Where is the plugin-registry.xml? From the settings.xml, you may enable it by setting to true and the file will be in ~/.m2/plugin-registry.xml How do I create a command line parameter (i.e., -Dname=value ) in my mojo? In your mojo, put "expression=${}" in your parameter field
You may now able to pass parameter values to the command line. "mvn -Dexpression.name=value install" How do I convert my from Maven 1 to Maven 2? In m1, we declare reports in the pom like this:
What does the "You cannot have two plugin executions with the same (or missing) elements" message mean? It means that you have executed a plugin multiple times with the same . Provide each with a unique then it would be ok. How do I add my generated sources to the compile path of Maven, when using modello? Modello generate the sources in the generate-sources phase and automatically adds the source directory for compilation in maven. So you don't have to copy the generated sources. You have to declare the modello-plugin in the build of your plugin for source generation (in that way the sources are generated each time). What is Maven's order of inheritance?
parent pom
project pom
settings
CLI parameters
where the last overrides the previous. How do I execute the assembly plugin with different configurations? Add this to your pom,
and run mvn install, this will execute the assembly plugin twice with different config. How do I configure the equivalent of maven.war.src of war plugin in Maven 2.0?
... org.apache.maven.plugins maven-war-plugin
...
How do I add main class in a generated jar's manifest? Configure the maven-jar-plugin and add your main class.
What does the FATAL ERROR with the message "Class org.apache.commons.logging.impl.Jdk14Logger does not implement Log" when using the maven-checkstyle-plugin mean? Checkstyle uses commons-logging, which has classloader problems when initialized within a Maven plugin's container. This results in the above message - if you run with '-e', you'll see something like the following: — Caused by: org.apache.commons.logging.LogConfigurationException: org.apache.commons.logging.LogConfigurationException: Class org.apache.commons.logging.impl.Jdk14Logger does not implement Log — buried deep in the stacktrace. The only workaround we currently have for this problem is to include another commons-logging Log implementation in the plugin itself. So, you can solve the problem by adding the following to your plugin declaration in your POM:
While this may seem a counter-intuitive way of configuring a report, it's important to remember that Maven plugins can have a mix of reports and normal mojos. When a POM has to configure extra dependencies for a plugin, it should do so in the normal plugins section. We will probably try to fix this problem before the next release of the checkstyle plugin. UPDATE: This problem has been fixed in the SVN trunk version of the checkstyle plugin, which should be released very soon. Plugins and Lifecycle, Sites & Reporting, Errors How do I determine the stale resources in a Mojo to avoid reprocessing them? This can be done using the following piece of code:
// At some point of your code StaleSourceScanner scanner = new StaleSourceScanner( 0, Collections.singleton( "**/*.xml" ), Collections.EMPTY_SET ); scanner.addSourceMapping( new SuffixMapping( ".xml", ".html" ) ); Set staleFiles = (Set) scanner.getIncludedSources( this.sourceDirectory, this.targetDirectory );
The second parameter to the StaleSourceScanner is the set of includes, while the third parameter is the set of excludes. You must add a source mapping to the scanner (second line). In this case we're telling the scanner what is the extension of the result file (.html) for each source file extension (.xml). Finally we get the stale files as a Set calling the getIncludedSources method, passing as parameters the source and target directories (of type File). The Maven API doesn't support generics, but you may cast it that way if you're using them. In order to use this API you must include the following dependency in your pom:
org.codehaus.plexus plexus-compiler-api 1.5.1
Is there a property file for plug-in configuration in Maven 2.0? No. Maven 2.x no longer supports plug-in configuration via properties files. Instead, in Maven 2.0 you can configure plug-ins directly from command line using the -D arguement, or from the plug-in's POM using the element. How do I determine which POM contains missing transitive dependency? run "mvn -X" How do I integrate static (x) html into my Maven site? You can integrate your static pages in this several steps,
Put your static pages in the resources directory, ${basedir}/src/site/resources.
Create your site.xml and put it in ${basedir}/src/site. An example below:
Maven War Plugin http://maven.apache.org/images/apache-maven-project.png http://maven.apache.org/