How to build same source code twice with different dependency version, in both Maven and Eclipse?


April 2019


16 time


I would like to build two different versions of a custom SonarQube (SQ) plugin; one for SonarQube 6.7.x LTS release, one for the latest 7.6 release. At the moment, I have a Maven structure similar to the following:

  • parent
    • common: Common code used by both tool and both plugin versions, doesn't use SQ API
    • tool: Some related command-line utility, doesn't use SQ API
    • plugin-6.7: Plugin code for SQ 6.7
    • plugin-7.6: Plugin code for SQ 7.6
    • dist: Builds a distribution zip containing the CLI utility, both plugin versions, dependency licenses and source code

Most of the source code and resources are the same for both plugin-6.7 and 7.6; only a small number of classes are different. As such I would like to move this common code to some shared source folder/module.

I would still like to compile this common code twice though, to verify the code compiles against both SQ API versions. In Eclipse this should show up as two separate source folders or projects, so I can easily verify that the common code doesn't use any SQ API's that are not yet available in 6.7 API, and doesn't use any API's that have been removed or deprecated in 7.6 API.

Preferably I would like to stick with building both plugin versions in a single build, so if possible I would like to avoid having to use two separate profiles.

Is this possible in any way?

What I have tried

With Maven I have found several ways for getting this to work, but I cannot get any of these approaches to work with m2eclipse.

Approach 1

Create a new module plugin-common, containing pom-6.7.xml and pom-7.6.xml. Both pom's are essentially the same apart from artifact id or classifier, and dependency on different SQ API version. Parent project defines these as 2 separate modules using


The issue with this approach is that I can't import these modules into Eclipse, as m2eclipse only supports pom.xml as the filename.

Approach 2

Similar to the above, but using separate sub-directories for the pom.xml files and using <sourceDirectory>${project.basedir}/../src/main/java</sourceDirectory> to point to the common source code:

  • plugin-common
    • src/main/java
    • src/main/resources
    • pom.xml: parent for 6.7 and 7.6 modules
    • 6.7/pom.xml
    • 7.6/pom.xml

This approach allows for importing both plugin-common versions into Eclipse, but Eclipse complains about 'Access .../src/main/java directory outside of project base directory'. As such it doesn't show any source code in the two plugin-common projects.

Approach 3

Don't have any pom.xml files in plugin-common, but instead add the common code as source folders to both plugin-6.7 and plugin-7.6 modules using build-helper-maven-plugin, using <source>${project.basedir}/../plugin-common/src/main/java</source>.

Again this fails in Eclipse due to the 'Access .../src/main/java directory outside of project base directory' warning.

0 answers