Ambuj Jauhari
Ambuj Jauhari

Reputation: 1299

Multiple java version in maven build

I am working on one of the modules of a multi-module project. I am developing a java plugin to deploy my gigaspace application in pre-integration-test phase in maven.

The build happens on Teamcity and current JAVA_HOME points to Java 6 on which whole repository is built. Now, when deploying the application in pre-integration-test phase, it needs Java 7 because it uses some 3rd party libraries which were compiled in Java 7.

Is there any way I can somehow use Java 7 for deploying my application in pre-integration-test phase, but use Java 6 for compilation?

Upvotes: 0

Views: 566

Answers (2)

mcoolive
mcoolive

Reputation: 4205

If the purpose is to generate JAVA 6 bytecode, then you can use JAVA 7 (JAVA_HOME points to JAVA 7) for the whole lifecycle that include integration tests, but configure the maven-compiler-plugin with the version 1.6:

<properties>
    <maven.compiler.source>1.6</maven.compiler.source>
    <maven.compiler.target>1.6</maven.compiler.target>
</properties>

Upvotes: 0

Kedar Mhaswade
Kedar Mhaswade

Reputation: 4695

It seems that this is not straightforward. If you look at the plugin goal that gets associated with the lifecycle phase named pre-integration-test, then perhaps you can control its execution configuration:

    <plugin>
          ...
          <execution>                                                               
            <id>...</id>                                            
            <phase>pre-integration-test</phase>                                             
            <goals>                                                                 
              <goal>...</goal>                                              
            </goals>                                                                
            <configuration>                                                         
              <source>1.7</source>                                                  
              <target>1.7</target>                                                  
            </configuration>                                                        
          </execution>                                                              
        </executions>  
   </plugin>

I haven't tried it myself. Also, see another somewhat similar question and its answer here. It's also useful to run mvn help:effective-pom to see what is going on.

Upvotes: 0

Related Questions