I have an aggregator project built in jenkins and I want to publish javadocs. So I installed javadoc plugin and changed my parent pom as follows:
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<aggregate>true</aggregate>
<outputDirectory>${project.build.directory}/apidocs</outputDirectory>
</configuration>
I tried different configurations but this is the only one that won't fail the build. With this configuration the build doesn't fail but no javadocs are to be found. Am I missing something here? Does anyone has the same problem?
First you should use the aggregate goal instead of the parameter cause it's marked deprecated.
Furthermore you should configure javadoc plugin like the following in your root pom like this:
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<!-- Default configuration for all reports -->
...
</configuration>
<executions>
<execution>
<id>aggregate</id>
<goals>
<goal>aggregate</goal>
</goals>
<phase>package</phase>
<configuration>
<!-- Specific configuration for the aggregate report -->
...
</configuration>
</execution>
...
</executions>
</plugin>
...
</plugins>
</build>
...
</project>
Afterwards you should be able just by:
mvn clean package
This will result in a folder in the root target/apidoc which contains the created aggregated javadocs.
I found a way to publish the javadocs as .jar. I used the above pom configuration with the small change:
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
It publishes javadocs as .jars for every sub-module. The javadocs are to be found in the sub-module directory not in the parent directory.
Specifically, I run the launch4j-maven-plugin plugin to generate me an .exe file. This only works on Windows, so I was wondering if I could 'opt-out' of this step on other platforms?
The plugin is tied to the execution phase like this
<plugin>
...
<execution>
<id>l4j-clui</id>
<phase>package</phase>
<goals>
<goal>launch4j</goal>
</goals>
</execution>
...
You can wrap that plugin under separate build profile and just enable that profile on the build that you want
For example:
<project>
...
<profile>
<id>generate-exe</id>
<build>
<plugins>
<plugin>
<!_- your plugin configuration -->
</plugin>
...
</plugins>
</build>
</profile>
...
</project>
Now pass parameter while launching maven to specify profile
For example:
mvn clean install -Pgenerate-exe
I am using the plugin to attached tests in the test of another module.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
And in the module where the jar is required:
<dependency>
<groupId>com.myco.app</groupId>
<artifactId>foo</artifactId>
<version>1.0-SNAPSHOT</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
</dependencies>
It has been very useful to me, but I have found a problem: When I execute "clean install -Dmaven.test.skip=true", also the dependency test-jar is required and the proccess fails
yes, because -Dmaven.test.skip=true just makes the maven junit plugins (surefire and failsafe) not execute - it prevents them from running any tests.
it does NOT prevent maven from trying to "collect" all of your test-scoped dependenies. maven still collects all of them.
if you want optional dependencies (regardless of what scope) you should read about maven profiles - you could define a profile in which this dependency will be defined and then maven will try and get it only if you activate the profile (from the command line, for example)
-Dmaven.skip.test or -DskipTests just skips the test execution, it still compiles test classes so it needs test dependencies
If you want to skip the compilation of test classes, you can configure maven compiler plugin to do so, more helpful would be to create separate build profile and skip compilation on demand by specifying special build profile
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<executions>
<execution>
<id>default-testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<skip>true</skip>
</configuration>
</execution>
</executions>
</plugin>
How do I set in the pom to not compile tests in Maven? I've tried:
<properties>
<skipTests>true</skipTests>
</properties>
but in that case, Maven compile the tests but don't run them. I need Maven don't compile my tests.
You have to define maven.test.skip to true.
<properties>
<maven.test.skip>true</maven.test.skip>
</properties>
http://maven.apache.org/surefire/maven-surefire-plugin/examples/skipping-test.html
In my case a solution was to put tests in a profile (e.g. runTests), so when I want to run these tests, I add the parameter -PrunTests. Thanks for the replies.
Configure maven-compiler-plugin to skip the compilation.
Once again, I do not recommend it.
<project>
<properties>
<maven.test.skip>true</maven.test.skip>
</properties>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<executions>
<execution>
<id>default-testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<skip>${maven.test.skip}</skip>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>
If you are using the surefire-plugin for executing tests, you can configure it to skip them based on a naming pattern:
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.14</version>
<configuration>
<includes>
<include>%regex[.*[Cat|Dog].*Test.*]</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
[...]
</project>
This, however, requires the tests file names to conform to the desired pattern(s). At work we are using this approach, and have our tests end with ..UnitTest or ..IntegrationTest, so that we can easily turn each of them off by modifying the regex in the corresponding build profile.
Take a look at Apache's documentation on the surefire plugin. You may find something more useful or better suited for your case.
I'm trying to execute grunt tasks from within maven without needing to install Node.js or anything. This is because I wan't my artifact to be packaged by Jenkins and I can't install Node.js on that machine.
I know that it's easy with npm and a few commands to get it working, but I also think that it should be easy to integrate with maven, the problem is that I don't know where to start since I'm new to npm.
Yes, using the frontend-maven-plugin, you can compile Grunt projects via Maven (found via the NodeJS mailing list).
As the documentation points out, the plugin has the following features:
Let you keep your frontend and backend builds as separate as possible, by reducing the amount of interaction between them to the bare minimum; using only 1 plugin.
Let you use Node.js and its libraries in your build process without installing Node/NPM globally for your build system
Let you ensure that the version of Node and NPM being run is the same in every build environment
I've walked through the code and it's fairly simple. Thank goodness someone finally put this together; it's an elegant solution. The repository includes an example that uses a regular Gruntfile.js to invoke jshint analysis.
UPDATE 2014-09-19: This is no longer the most accurate answer - please take a look at some of the other answers below. It was accurate at the time when I answered the question, but there seems to have been a good deal of progress in this area since then.
I'm afraid you're out of luck. Grunt is built using node and needs to be installed using npm. You might be able to copy an existing installation of Grunt from another machine if you don't want to use npm, but will still use the grunt executable and all of its dependencies on your build server.
In addition to that, many of the Grunt tasks are implemented as Node.js modules, and you will have to install them as well. Again, you might be able to copy them from another server, where you've done the Node.js/Grunt installation, but at one point, you have to do it.
For running Grunt from Maven, your best bet is to use the Maven exec plugin and then execute the grunt executable from there.
As an alternative, there are several Maven plugins that allow you to do things similar to Grunt in a Java-based fashion. They require additional configuration not compatible with Grunt, so YMMV. One that I've used in the past is http://code.google.com/p/wro4j/, which comes with a Maven plugin as well: http://code.google.com/p/wro4j/wiki/MavenPlugin
Any particular reason why you can't install Node.js on your build server?
You can use grunt-maven-plugin. It allows you to easily integrate Grunt tasks into Maven build process. No dirty hacks.
This is what I use in my current project and it works just perfect.
Finally I ended up with this (which is close enough but doesn't solve the problem):
<plugin>
<groupId>org.mule.tools.javascript</groupId>
<artifactId>npm-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>fetch-modules</goal>
</goals>
<configuration>
<packages>
<package>grunt-cli:0.1.6</package>
</packages>
</configuration>
</execution>
</executions>
</plugin>
that installs locally the grunt-cli, but if I don't have installed node.js it's worthless. Although I try to install node.js locally there's the need to have installed python, g++ and make. So I'll go with the KISS solution: install grunt in the build server.
References:
https://github.com/mulesoft/npm-maven-plugin
https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager
https://github.com/mcheely/requirejs-maven-plugin
You might want to checkout http://jhipster.github.io/ : it's a Yeoman generator, that generates an application which has Maven, Grunt and Bower all working together.
It's a bit like your third option, but everything is configured for you, which isn't that easy. It's also generating the basic AngularJS and Java REST services for you
This is a full copy/paste solution which work in 2017 using frontend-maven-plugin for front build, and maven-war-plugin to build the war.
What it does ? install npm, bower grunt,and everything you need, then run npm install, bower install and finally grunt build.
You can remove/add replace the steps you want, for me it's a full 30 sec install/build library and project.
<dependencies>
...
</dependencies>
<dependencyManagement>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.github.eirslett/frontend-maven-plugin -->
<dependency>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceDirectory>src/main/webapp/YourFrontJsFolder/dist</warSourceDirectory>
<warName>YouWarName</warName>
<failOnMissingWebXml>false</failOnMissingWebXml>
<warSourceExcludes>node_modules/**</warSourceExcludes>
<includeScope>system</includeScope>
<webResources>
<resource>
<directory>WebContent/WEB-INF</directory>
<targetPath>WEB-INF</targetPath>
<includes>
<include>**/*.jar</include>
<include>**/*.jsp</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>Cp1252</encoding>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<finalName>YourAppName</finalName>
</build>
<profiles>
<profile>
<id>release</id>
<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<executions>
<execution>
<!-- optional: you don't really need execution ids, but it looks
nice in your build log. -->
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<!-- optional: default phase is "generate-resources" -->
<phase>generate-resources</phase>
<configuration>
<nodeVersion>v7.6.0</nodeVersion>
</configuration>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<!-- optional: default phase is "generate-resources" -->
<phase>generate-resources</phase>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
<execution>
<id>bower install</id>
<goals>
<goal>bower</goal>
</goals>
<configuration>
<!-- optional: The default argument is actually "install", so unless
you need to run some other bower command, you can remove this whole <configuration>
section. -->
<arguments>install</arguments>
</configuration>
</execution>
<execution>
<id>grunt build</id>
<goals>
<goal>grunt</goal>
</goals>
<!-- optional: the default phase is "generate-resources" -->
<phase>generate-resources</phase>
<configuration>
<!-- optional: if not specified, it will run Grunt's default task
(and you can remove this whole <configuration> section.) -->
<arguments>build</arguments>
</configuration>
</execution>
</executions>
<configuration>
<installDirectory>target</installDirectory>
<workingDirectory>src/main/webapp/YourFrontJsFolder</workingDirectory>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>debug</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>IDE</id>
<activation>
<property>
<name>m2e.version</name>
</property>
</activation>
<build>
<!-- Put the IDE's build output in a folder other than target, so that
IDE builds don't interact with Maven builds -->
<directory>target-ide</directory>
</build>
</profile>
</profiles>
Then you can Run as -> Maven build ..., with goal clean install and profile release
The first problem is that Maven is Java, but Grunt.js runs on the Node.js runtime. The easiest integration I ever achieved between the two involved the maven-exec-plugin. The maven-exec-plugin is capable of executing .sh/.bat/.cmd scripts, whichever are native to the OS you are using. So during a Maven build I would have the maven-exec-plugin execute a script named optimize-js.sh, for example, which would simply do something like “grunt release –force”, or whatever. The scripts can be made to do whatever. The important thing is to configure the maven-exec-plugin to execute them in the correct working directory. Of course, “grunt” and “node” need to be executable from the command-line.
If the problem is installing NodeJS on the Jenkins machine then you can use the NodeJS Jenkins plugin.
https://wiki.jenkins-ci.org/display/JENKINS/NodeJS+Plugin
We're not using it with Maven (yet) but we've got grunt running.
Can be done with exec-maven-plugin.
Define a script and dependency to grunt-cli in your package.json:
...
"scripts": {
"build": "./node_modules/.bin/grunt install"
},
"devDependencies": {
"grunt-cli": "^1.2.0",
...
In your pom, add the commands to run:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>X.Y.Z</version>
<executions>
<execution>
<id>exec-npm-install</id>
<phase>generate-sources</phase>
<configuration>
<workingDirectory>${project.basedir}</workingDirectory>
<executable>npm</executable>
<arguments>
<argument>install</argument>
</arguments>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
<execution>
<id>exec-grunt-install</id>
<phase>generate-sources</phase>
<configuration>
<workingDirectory>${project.basedir}</workingDirectory>
<executable>npm</executable>
<arguments>
<argument>run</argument>
<argument>build</argument>
</arguments>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
It will now run on mvn package