Execute Maven plugin goal on parent module, but not on children - version-control

We have a multi-module maven project that uses a profile that defines a buildnumber-maven-plugin to increment a build number and then check it into source control.
If I define the plugin in the parent pom.xml it executes for all the child builds as well.
Here's my parent pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.webwars</groupId>
<artifactId>parent</artifactId>
<packaging>pom</packaging>
<properties>
<buildNumber.properties>${basedir}/../parent/buildNumber.properties</buildNumber.properties>
</properties>
<version>1.0-SNAPSHOT</version>
<name>Parent Project</name>
<profiles>
<profile>
<id>release</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<debug>false</debug>
<optimize>true</optimize>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.0-beta-3</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
<buildNumberPropertiesFileLocation>${buildNumber.properties}</buildNumberPropertiesFileLocation>
<getRevisionOnlyOnce>true</getRevisionOnlyOnce>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
<format>{0, number}</format>
<items>
<item>buildNumber</item>
</items>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>checkin</goal>
</goals>
</execution>
</executions>
<configuration>
<basedir>${basedir}</basedir>
<includes>buildNumber.properties</includes>
<message>[Automated checkin] of ${basedir} Build version: ${major.version}.${minor.version}.${buildNumber}</message>
<developerConnectionUrl>...</developerConnectionUrl>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<modules>
<module>../common</module>
<module>../data</module>
<module>../client</module>
<module>../webplatform</module>
</modules>
...
</project>

As documented in the Plugins section of the pom reference:
Beyond the standard coordinate of groupId:artifactId:version, there are elements which configure the plugin or this builds interaction with it.
inherited: true or false, whether or not this plugin configuration should apply to POMs which inherit from this one.
So just add <inherited>false</inherited> to the buildnumber-maven-plugin configuration to avoid inheritance in children POMs:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.0-beta-3</version>
<inherited>false</inherited>
...
</plugin>

You can add <inherited>false</inherited> to the plugin configuration to avoid inheritance in children POMs:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.0-beta-3</version>
<inherited>false</inherited>
...
</plugin>
Or, if your plugin has multiple executions, you can control which executions are inherited and which are not by adding the inherited tag to the execution body:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>parent-only</id>
<phase>initialize</phase>
<inherited>false</inherited>
<configuration>
<target>
<echo message="Echoed only by this module."/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>all-modules</id>
<phase>initialize</phase>
<inherited>true</inherited> <!-- Defaults to true, so you could leave this line out -->
<configuration>
<target>
<echo message="Echoed in this module and each child module."/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>

There is a built-in maven option:
mvn --help
...
-N,--non-recursive Do not recurse into sub-projects

If the plugin is custom one and you have access to plugin MOJO code, you can mark the plugin as aggregator; if the expected behavior is applicable for all projects where plugin is to be used.
As mentioned in Mojo API Specification ,
Flags this Mojo to run it in a multi module way, i.e. aggregate the
build with the set of projects listed as modules.
Example,
#Mojo(name = "createHF", inheritByDefault = false, aggregator = true)
public class CreateHFMojo extends AbstractMojo {
..
public void execute() throws MojoExecutionException, MojoFailureException {
....
}
..
}
Detailed example on github.

Just an addition to the great answers here: note that per-execution inheritance is broken in Maven 2: http://jira.codehaus.org/browse/MNG-3959

Related

Multi module Scala project gives 0% sonar code coverage

I am using SonarQube Enterprise EditionVersion 7.9.1. I am running maven goal for my multi-module scala project as :
mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent verify org.sonarsource.scanner.maven:sonar-maven-plugin:3.4.0.905:sonar
After successfull completion, I am getting 0% code coverage. Below is my sonar.properties:
sonar.junit.reportsPath=target/surefire-reports
sonar.surefire.reportsPath=target/surefire-reports
sonar.jacoco.reportPath=target/coverage-reports/jacoco-unit.exec
sonar.binaries=target/classes
sonar.java.coveragePlugin=jacoco
sonar.verbose=true
Below is pom.xml
<modules>
<module>1</module>
<module>2/module>
<module>3</module>
<module>4</module>
</modules>
<properties>
<!-- Sonar -->
<sonar.version>3.7.0.1746</sonar.version>
<jacoco.version>0.7.9</jacoco.version>
<sonar.projectName>ds</sonar.projectName>
<sonar.projectDescription>**</sonar.projectDescription>
<sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin>
<sonar.jacoco.reportPaths>${project.build.directory}/jacoco.exec</sonar.jacoco.reportPaths>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.language>scala</sonar.language>
<sonar.sources>src/main</sonar.sources>
<!--<sonar.tests>src/test</sonar.tests> -->
<scoverage.plugin.version>1.4.1</scoverage.plugin.version>
<sonar.scala.scoverage.reportPath>target/scoverage.xml</sonar.scala.scoverage.reportPath>
<junit.version>4.11</junit.version>
<!-- Sonar -->
</properties>
<profiles>
<!-- Sonar -->
<profile>
<id>coverage-per-test</id>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report-aggregate</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<dataFile>target/jacoco.exec</dataFile>
<!-- Sets the output directory for the code coverage report. -->
<outputDirectory>target/jacoco-ut</outputDirectory>
</configuration>
</execution>
</executions>
<configuration>
<systemPropertyVariables>
<jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<!-- Sonar -->
</profiles>
</project>
I am getting the coverage as 0%, when there are many unit test written. How should I fix this?

Eclipse m2e overwrites buildNumber from buildnumber-maven-plugin

I'm using Eclipse m2e, buildnumber-maven-plugin, and templating-maven-plugin to create a filtered java file with ${buildNumber}.
Here is a sample from the src/main/java-templates/build.java file:
public static final String BUILDNUMBER = "${buildNumber}";
If I run "mvn generate-sources" on the command line, my filtered java file contains the generated buildNumber value. If I run "generate-sources" from within Eclipse using m2e, the filtered java file briefly contains the actual buildNumber but is quickly replaced with the original string "${buildNumber}"
The structure of the project is
CmbProduct/pom.xml
+-- Model/pom.xml
+-- other modules
The buildnumber-maven-plugin is run in the parent pom.xml because I use buildNumber to set a general <finalName> value for all sub-modules.
I have tried it with and without lifecycle-mapping for org.eclipse.m2e.
I did not notice any change.
I have several "echo" tasks in both pom.xml files for debug purposes. These show the correct/actual buildNumber when run.
Here is an abbreviated CmbProduct/pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.magnicomp</groupId>
<artifactId>Product</artifactId>
<!-- Do not change version EVER. This is used by MagniCompCommon and all other sub modules. -->
<version>1.0</version>
<packaging>pom</packaging>
<name>CMB Product</name>
<modules>
<module>Model</module>
<module>Common</module>
</modules>
<scm>
<!-- SCM used by buildnumber-maven-plugin and others -->
<connection>scm:git:git://sol:/vol/git/cmb.git</connection>
</scm>
<properties>
<!--
The canonical Product Version is defined below. This value is
automatically propagated to Java via plugin in the Modelproject.
The ${buildNumber} is automatically generated on-the-fly by
buildnumber-maven-plugin
-->
<!--
Product version defined primary version of product.
This is used instead of project.version because the later must
remain the same.
-->
<product.version.base>1.0.0</product.version.base>
<product.version.status>alpha1</product.version.status>
<product.version>${product.version.base}.${buildNumber}-${product.version.status}</product.version>
<!-- Version in 4 dot (digits + dot) format suitable for Windows file Version -->
<product.version.4dot>${product.version.base}.${buildNumber}</product.version.4dot>
<!-- Java version -->
<project.source.version>1.8</project.source.version>
<project.target.version>1.8</project.target.version>
<!-- MagniComp common -->
<failOnMissingWebXml>false</failOnMissingWebXml>
<hibernate.version>4.3.11.Final</hibernate.version> <!-- was 4.3.10.Final -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<texo.version>0.9.0-v201501182340</texo.version>
<emf.version>2.11.0-v20150123-0347</emf.version>
<!-- Vaadin -->
<vaadin.version>7.5.7</vaadin.version>
<vaadin.plugin.version>${vaadin.version}</vaadin.plugin.version>
<vaadin.icons.version>1.0.1</vaadin.icons.version>
<!-- Product specific -->
<javax.servlet.version>3.1</javax.servlet.version>
<jersey.glassfish.version>2.21</jersey.glassfish.version>
<bouncy.version>1.51</bouncy.version>
<build.helper.maven.plugin.version>1.9.1</build.helper.maven.plugin.version>
<maven.shade.plugin.version>2.4.1</maven.shade.plugin.version>
<jna.version>4.1.0</jna.version>
</properties>
<build>
<finalName>${project.artifactId}-${product.version}</finalName>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<configuration>
<encoding>${project.encoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<!-- We do not need a default assembly.xml
<configuration>
<descriptors>
<descriptor>src/main/assembly/bin.xml</descriptor>
</descriptors>
</configuration>
-->
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.4.0</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>templating-maven-plugin</artifactId>
<version>1.0.0</version>
</plugin>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<versionRange>[1.4,)</versionRange>
<goals>
<goal>create</goal>
<goal>create-metadata</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute>
<runOnIncremental>true</runOnIncremental>
</execute>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<encoding>${project.encoding}</encoding>
<source>${project.source.version}</source>
<target>${project.target.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.4</version> <!-- Keep in sync with pluginsManagement -->
<inherited>false</inherited> <!-- Run only for this level project -->
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal> <!-- Create buildNumber -->
<goal>create-metadata</goal> <!-- Create build.properties -->
</goals>
</execution>
</executions>
<configuration>
<!--
Auto update incremental integer as build number.
Without this it uses git revision.
-->
<format>{0,number,integer}</format>
<items>
<item>buildNumber</item>
</items>
<!-- Store buildNumber in given file. Use product.version so it resets each time version changes -->
<buildNumberPropertiesFileLocation>${basedir}/buildinfo/buildNumber-${product.version.base}-${product.version.status}.properties</buildNumberPropertiesFileLocation>
<!-- WORKAROUND: Make ${buildNumber} available to child modules -->
<getRevisionOnlyOnce>true</getRevisionOnlyOnce>
</configuration>
</plugin>
<plugin> <!-- Help identify buildNumber -->
<artifactId>maven-antrun-plugin</artifactId>
<inherited>false</inherited> <!-- Run only for this level project -->
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>Build Number (buildNumber) is ${buildNumber}</echo>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<!-- This plugin allows us to add "src-gen" as another source dir -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>${build.helper.maven.plugin.version}</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals><goal>add-source</goal></goals>
<configuration>
<sources>
<source>src-gen</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng-unit.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
... snip ....
Here is Model/pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.magnicomp</groupId>
<artifactId>Product</artifactId>
<version>1.0</version>
</parent>
<artifactId>Model</artifactId>
<packaging>jar</packaging>
<build>
<resources> <!-- XXX ARE WE GOING TO USE THIS? -->
<resource>
<directory>src/main/resources</directory>
<includes>
<include>version.properties</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
<!-- Override eclipse error about "create-metadata" goal from above plugin -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.codehaus.mojo</groupId>
<artifactId>templating-maven-plugin</artifactId>
<versionRange>[1.0.0,)</versionRange>
<goals>
<goal>filter-sources</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute>
<runOnIncremental>true</runOnIncremental>
</execute>
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<versionRange>[1.4,)</versionRange>
<goals>
<goal>create</goal>
<goal>create-metadata</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute>
<runOnIncremental>true</runOnIncremental>
</execute>
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<versionRange>[1.3,)</versionRange>
<goals>
<goal>run</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin> <!-- Aid with making sure buildNumber is available -->
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>echo-buildnumber-1</id>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>Build number during validate is ${buildNumber}</echo>
</tasks>
</configuration>
</execution>
<execution>
<id>echo-buildnumber-2</id>
<phase>generate-sources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>Build number during generate-sources is ${buildNumber}</echo>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
<plugin> <!-- Must be after buildnumber-maven-plugin due to ${buildNumber} -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>templating-maven-plugin</artifactId>
<executions>
<!-- Take files in sourceDirectory and filter them to outputDirectory -->
<execution>
<id>filter-src</id>
<phase>generate-sources</phase>
<goals>
<goal>filter-sources</goal>
</goals>
<configuration>
<sourceDirectory>${basedir}/src/main/java-templates</sourceDirectory>
<outputDirectory>${basedir}/src-generated</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<!-- Copy the build.properties created by buildnumber-maven-plugin -->
<id>copy-build-properties</id>
<phase>validate</phase>
<goals> <goal>copy-resources</goal> </goals>
<configuration>
<outputDirectory>${basedir}/src/main/resources</outputDirectory>
<resources>
<resource>
<directory>${project.parent.basedir}/target/generated/build-metadata</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
... snip ...
Its been a while, but I got this work with the create-timestamp goal with the timestampFormat and timestampPropertyName configuration properties, and the by adding the runOnConfiguration true on the Eclipse m2e lifecycle mapping.
Build number plugin:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.4</version>
<configuration>
<revisionOnScmFailure>just.say.no.scm.config.in.pom</revisionOnScmFailure>
</configuration>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create-timestamp</goal>
</goals>
<configuration>
<timestampFormat>yyyyMMddHHmmssS</timestampFormat>
<timestampPropertyName>myBuildNumberVariable</timestampPropertyName>
<!-- formats the timestamp all together like 20160404141705123 and puts
it in the ${myBuildNumberVariable} buildProperty -->
</configuration>
</execution>
</executions>
</plugin>

Automatic update of generated css files via m2e

I'm using the lesscss-maven-plugin to generate different css files to the target directory (target\generated-sources) and then use maven-war-plugin to add this directory as an webResouce. Those files will generate perfectly fine.
However the m2e-plugin (version 1.0.0) won't copy those files in the according web-resources folder (m2e-wtp\web-resources), when they have changed. Only when I run a eclipse "maven/update project" changes will be updated. But I want the changes to take affect automatically, when the files have changed. Here is my pom configuration:
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions><pluginExecution>
<pluginExecutionFilter>
<groupId>org.lesscss</groupId>
<artifactId>lesscss-maven-plugin</artifactId>
<versionRange>[1.3.3]</versionRange>
<goals>
<goal>compile</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute>
<runOnIncremental>true</runOnIncremental>
<runOnConfiguration>true</runOnConfiguration>
</execute>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
....
<plugin>
<groupId>org.lesscss</groupId>
<artifactId>lesscss-maven-plugin</artifactId>
<version>1.3.3</version>
<configuration>
<sourceDirectory>${project.basedir}/src/main/less</sourceDirectory>
<outputDirectory>${project.build.directory}/generated-sources/styles</outputDirectory>
<lessJs>${project.basedir}/tools/less/less-1.7.0.min.js</lessJs>
<includes>
<include>backend/backend-main.less</include>
<include>frontend/frontend-main.less</include>
</includes>
</configuration>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<webResources>
<resource>
<directory>${project.build.directory}/generated-sources/styles</directory>
<targetPath>styles</targetPath>
</resource>
</webResources>
</configuration>
</plugin>
There are two options:
Use an m2e specific profile
This is similar to the workaround you found, but a bit cleaner as it activates the profile only on m2e and you use a property to set an alternative value for when you package not using m2e.
You create an m2e specific profile that, when activated, will put the files directly in the m2e-wtp/web-resources/styles directory
<properties>
<lesscss.outputDirectory>${project.build.directory}/${project.build.finalName}/styles</lesscss.outputDirectory>
</properties>
<profiles>
<profile>
<id>m2e</id>
<activation>
<property>
<name>m2e.version</name>
</property>
</activation>
<properties>
<lesscss.outputDirectory>${project.build.directory}/m2e-wtp/web-resources/styles</lesscss.outputDirectory>
</properties>
</profile>
</profiles>
<plugin>
<groupId>org.lesscss</groupId>
<artifactId>lesscss-maven-plugin</artifactId>
<version>1.3.3</version>
<configuration>
<sourceDirectory>${project.basedir}/src/main/webapp/styles</sourceDirectory>
<outputDirectory>${lesscss.outputDirectory}</outputDirectory>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
<phase>process-sources</phase>
</execution>
</executions>
</plugin>
Source: https://github.com/marceloverdijk/lesscss-maven-plugin/issues/8
Use m2e-wro4j
It promises to:
execute wro4j-maven-plugin:run on Eclipse incremental builds, if a change is detected on css, js, less, json, sass resources under wro4j-maven-plugin's contextFolder (src/main/webapp by default)
Source: https://github.com/jbosstools/m2e-wro4j
The idea for my actual workaround was to modify the css file in target\m2e-wtp by "hand".
(First I tried to copy the css files from target\generated-sources to target\m2e-wtp with the maven-resource-plugin, but for a unkown reason, even the maven-resource-plugin was not coping when the filed css files in target\generated-sources gets updated.)
So I came up with this soution: let the lesscss-maven-plugin generate the files twice, one bunch to target\generated-sources and the second one to target\m2e-wtp. Of course the lesscss-maven-plugin has only one output folder, so one has to run the less:compile goal twice. (This is a bit slow, but it works.)
Because one need the second bunch of css files only in eclipse I have added the second execution to an profile.
<profile>
<id>less-eclipse-m2e-workarround</id>
<!--
problem: Eclipse is not updating m2e-wtp folder when css files in generated-sources get modified
workarround: generate the css twice: the normal nonce for generated-sources and a second bunch (only
for eclipse) directly into m2e-wtp folder
to enable this profile add the profile-id to: project/properties/maven/active maven profiles
details: http://stackoverflow.com/questions/23521410/automatic-update-of-generated-css-files-via-m2e
-->
<build>
<plugins>
<plugin>
<groupId>org.lesscss</groupId>
<artifactId>lesscss-maven-plugin</artifactId>
<executions>
<execution>
<id>for-eclipse</id>
<phase>generate-resources</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/m2e-wtp/web-resources/styles</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

Tycho: Categorize p2 metadata

Iam trying to generate a categorized p2 repository with Tycho. There are basically three steps to make (compare Eclipse documentation):
Download Bundles
Trigger org.eclipse.equinox.p2.publisher.FeaturesAndBundlesPublisher
Trigger org.eclipse.equinox.p2.publisher.CategoryPublisher
which i configured in a maven pom-file. Steps 1 and 2 are doing well whereas step 3 fails with:
Status ERROR: this code=0 publishing result null children=[Status ERROR: org.eclipse.equinox.p2.updatesite code=0 Error
generating category xml action. org.eclipse.equinox.p2.core.ProvisionException: Error reading update site file:/<path>/category.xml.]
Here is my pom.file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001 XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>demo</groupId>
<artifactId>simple-p2-repository</artifactId>
<version>0.1.0-SNAPSHOT</version>
<name>Simple p2 repository build</name>
<packaging>pom</packaging>
<properties>
<tycho-version>0.18.0</tycho-version>
</properties>
<build>
<plugins>
<!-- Step 1 -->
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-bundles-for-publishing</id>
<phase>process-resources</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-bundle</artifactId>
<version>2.7.5</version>
</artifactItem>
</artifactItems>
<outputDirectory>${project.basedir}/target/source/plugins</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<!-- Step 2 -->
<plugin>
<groupId>org.eclipse.tycho.extras</groupId>
<artifactId>tycho-p2-extras-plugin</artifactId>
<version>${tycho-version}</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>publish-features-and-bundles</goal>
</goals>
</execution>
</executions>
<configuration>
<compress>true</compress>
<append>true</append>
<publishArtifacts>true</publishArtifacts>
</configuration>
</plugin>
<!-- Step3 -->
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-p2-plugin</artifactId>
<version>${tycho-version}</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>category-p2-metadata</goal>
</goals>
</execution>
</executions>
<configuration>
<target>${basedir}/target/repository</target>
<categoryDefinition>${basedir}/category.xml</categoryDefinition>
</configuration>
</plugin>
</plugins>
</build>
</project>
And my category.xml
<?xml version="1.0" encoding="UTF-8"?>
<site>
<category-def name="all" label="Maven osgi-bundles"/>
<iu>
<category name="all"/>
<query>
<expression type="match">providedCapabilities.exists(p | p.namespace == 'osgi.bundle')</expression>
</query>
</iu>
</site>
If i manually execute the steps the same error occurs. What am i missing?
Although it is theoretically possible to call the low-level p2 actions via Tycho, I wouldn't recommend this approach for the problem you are trying to solve.
The artifact is already available in a Maven repository, so you can easily add it to the target platform of a Tycho build via pomDependencies=consider. Then you can for example build a p2 repository with the artifact, using Tycho's packaging type eclipse-repository.
You'll need the following POM configuration...
...
<packaging>eclipse-repository</packaging>
<dependencies>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-bundle</artifactId>
<version>2.7.5</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<version>${tycho-version}</version>
<configuration>
<pomDependencies>consider</pomDependencies>
</configuration>
</plugin>
</plugins>
</build>
... and a category.xml which explicitly lists the bundles you want to include:
<?xml version="1.0" encoding="UTF-8"?>
<site>
<bundle id="org.apache.cxf.bundle" version="0.0.0">
<category name="all"/>
</bundle>
<category-def name="all" label="Maven osgi-bundles"/>
</site>

How to generate an aggregated scaladoc for a maven site?

I have a multi-module Maven build and I would like to generate an aggregated Scaladoc in my root module, similar to what the aggregate goal for the maven-javadoc-plugin does. My first attempt was:
<project ...>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<configuration>
<reportPlugins>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
</plugin>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<reports>
<report>doc</report>
</reports>
<configuration>
<aggregateDirectOnly>false</aggregateDirectOnly>
<sendJavaToScalac>false</sendJavaToScalac>
</configuration>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<reports>
<report>aggregate</report>
</reports>
</plugin>
</reportPlugins>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
However, the aggregateDirectOnly property does not seem to have any effect. I always get the Scaladoc for the individual jar-type POMs only.
I also tried to set forceAggregate to true, but it had no effect, too.
How to do this?
This doesn't answer the question exactly as asked, but is a solution that may actually be preferred for mixed java/scala projects until ScalaDoc is capable of parsing JavaDoc comments. It produces a single aggregated JavaDoc that includes documentation from all of the project's Scala source files as well.
The solution is simple: configure Maven to use the GenJavaDoc Scala compiler plugin so that ScalaDocs can be converted to JavaDocs. Then, use the normal javadoc:aggregate goal to aggregate the project as normal.
Here is a sample Maven profile to do this. It configures the Scala compiler to generate the JavaDocs corresponding to the Scala sources, configures Maven to treat the genjavadoc directory created by the Scala compiler as a source directory, and then configures the javadoc plugin itself (this last may be optional if you have no special JavaDoc plugin configuration requirements).
<profile>
<id>javadoc</id>
<build>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<executions>
<execution>
<id>doc</id>
<phase>generate-sources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<configuration>
<args>
<arg>-P:genjavadoc:out=${project.build.directory}/genjavadoc</arg>
</args>
<compilerPlugins>
<compilerPlugin>
<groupId>com.typesafe.genjavadoc</groupId>
<artifactId>genjavadoc-plugin_${scala.binary.full.version}</artifactId>
<version>0.4</version>
</compilerPlugin>
</compilerPlugins>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/genjavadoc</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9</version>
<configuration>
<minmemory>64m</minmemory>
<maxmemory>2g</maxmemory>
<outputDirectory>${project.build.directory}</outputDirectory>
<detectLinks>true</detectLinks>
</configuration>
</plugin>
</plugins>
</build>
</profile>