maven - How to support different versions of main (and test) source sets for different Java versions (6, 7, 8) -



maven - How to support different versions of main (and test) source sets for different Java versions (6, 7, 8) -

i have library project in java. want implement, test, , release several versions of project, intented used different java versions: 6, 7, 8.

the simpliest way copy-paste project , back upwards several source trees, want avoid because it's tedious , error-prone.

another possible way factor "base" project, , several java version specific projects depending. versions differs slightly, don't reflect technical development issue in class hierarchy.

so i'm looking for

a kind of precompilers and/or standard maven options and/or maven plugins

which help back upwards several java version-specific versions of library single source tree, , transparently lib users.

you can generate 1 jar each java version (6, 7, 8) single pom.xml file.

all relevant work takes place in maven-compiler-plugin:compile mojo.

the trick execute mojo 3 times, each time writing resulting file different outputfilename. cause compiler run multiple times, each time using different versions , spitting appropriately named file.

<plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-compiler-plugin</artifactid> <version>3.1</version> <executions> <execution> <id>compile-1.6</id> <goals> <id>compile</id> </goals> <phase>compile</phase> <configuration> <source>1.6</source> <target>1.6</target> <executable>${env.java_home_6}/bin/javac</executable> <outputfilename>mylib-1.6.jar</outputfilename> </configuration> <!-- start edit --> <dependencies> <dependency> <groupid>com.mycompany</groupid> <artifactid>abc</artifactid> <version>1.0</version> </dependency> </dependencies> <!-- end edit --> </execution> <execution> <id>compile-1.7</id> <phase>compile</phase> <goals> <id>compile</id> </goals> <configuration> <source>1.7</source> <target>1.7</target> <executable>${env.java_home_7}/bin/javac</executable> <outputfilename>mylib-1.7.jar</outputfilename> </configuration> <!-- start edit --> <dependencies> <dependency> <groupid>com.mycompany</groupid> <artifactid>xyz</artifactid> <version>2.0</version> </dependency> </dependencies> <!-- end edit --> </execution> <!-- 1 more execution 1.8, elided save space --> </executions> </plugin>

hope helps.

edit

re: additional requirement each run compile against different sources.

see edits pom snippet above.

each execution can define own dependencies library list.

so jdk6 build depends on abc.jar jdk7 depends on xyz.jar.

java maven java-8 conditional-compilation

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -