title: maven multi module project, compile one of the modules with a different java version
body: <p>I am trying to build a maven multimodule project, where I want two of the modules to build on java 8 and one of them to build on java 7</p>
  
  <p>EDIT: I also looked at <a href="https://stackoverflow.com/questions/12414209/compile-maven-module-with-different-java-version">this SO question</a></p>
  
  <p>So I tried the solutions provided at <a href="https://vladmihalcea.com/maven-and-java-multi-version-modules/comment-page-1/#comment-7513" rel="nofollow noreferrer">Maven and Java multi-version modules</a></p>
  
  <p>So my parent pom looks like</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;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"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;com.example&lt;/groupId&gt;
      &lt;artifactId&gt;parent&lt;/artifactId&gt;
      &lt;name&gt;parent&lt;/name&gt;
      &lt;version&gt;1.0.0-SNAPSHOT&lt;/version&gt;
      &lt;description&gt;Parent pom &lt;/description&gt;
      &lt;packaging&gt;pom&lt;/packaging&gt;
  
      &lt;properties&gt;
          &lt;aspectj.version&gt;1.8.5&lt;/aspectj.version&gt;
          &lt;jackson.version&gt;2.4.0&lt;/jackson.version&gt;
          &lt;java.version&gt;1.8&lt;/java.version&gt;
          &lt;java.source.version&gt;${java.version}&lt;/java.source.version&gt;
          &lt;java.target.version&gt;${java.version}&lt;/java.target.version&gt;
          &lt;jdk.version&gt;8&lt;/jdk.version&gt;
          &lt;jdk&gt;${env.JAVA_HOME_8}&lt;/jdk&gt;
          &lt;jersey.version&gt;2.9&lt;/jersey.version&gt;
          &lt;groovy.version&gt;2.4.3&lt;/groovy.version&gt;
          &lt;slf4j.version&gt;1.7.9&lt;/slf4j.version&gt;
          &lt;spock.version&gt;1.0-groovy-2.4&lt;/spock.version&gt;
          &lt;spring.boot.version&gt;1.3.5.RELEASE&lt;/spring.boot.version&gt;
          &lt;spring.version&gt;4.2.6.RELEASE&lt;/spring.version&gt;
          &lt;spring.security.version&gt;3.1.7.RELEASE&lt;/spring.security.version&gt;
          &lt;spring.data.version&gt;1.7.0.RELEASE&lt;/spring.data.version&gt;
      &lt;/properties&gt;
  
      &lt;dependencyManagement&gt;
  
      &lt;/dependencyManagement&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.18.1&lt;/version&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;id&gt;unit-tests&lt;/id&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;test&lt;/goal&gt;
                          &lt;/goals&gt;
                          &lt;phase&gt;test&lt;/phase&gt;
                          &lt;configuration&gt;
                              &lt;includes&gt;
                                  &lt;include&gt;**/*Test.*&lt;/include&gt;
                                  &lt;include&gt;**/*Spec.*&lt;/include&gt;
                              &lt;/includes&gt;
                              &lt;excludes&gt;
                                  &lt;exclude&gt;**/*IntegrationTest.*&lt;/exclude&gt;
                              &lt;/excludes&gt;
                          &lt;/configuration&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-release-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.5&lt;/version&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
                  &lt;artifactId&gt;build-helper-maven-plugin&lt;/artifactId&gt;
                  &lt;version&gt;1.7&lt;/version&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;id&gt;add-source&lt;/id&gt;
                          &lt;phase&gt;generate-sources&lt;/phase&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;add-source&lt;/goal&gt;
                          &lt;/goals&gt;
                          &lt;configuration&gt;
                              &lt;sources&gt;
                                  &lt;source&gt;src/main/groovy&lt;/source&gt;
                              &lt;/sources&gt;
                          &lt;/configuration&gt;
                      &lt;/execution&gt;
                      &lt;execution&gt;
                          &lt;id&gt;add-test-source&lt;/id&gt;
                          &lt;phase&gt;generate-test-sources&lt;/phase&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;add-test-source&lt;/goal&gt;
                          &lt;/goals&gt;
                          &lt;configuration&gt;
                              &lt;sources&gt;
                                  &lt;source&gt;src/test/groovy&lt;/source&gt;
                                  &lt;source&gt;src/test/java&lt;/source&gt;
                              &lt;/sources&gt;
                          &lt;/configuration&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                  &lt;version&gt;3.3&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;compilerId&gt;groovy-eclipse-compiler&lt;/compilerId&gt;
                      &lt;source&gt;${java.source.version}&lt;/source&gt;
                      &lt;target&gt;${java.target.version}&lt;/target&gt;
                      &lt;showDeprecation&gt;true&lt;/showDeprecation&gt;
                      &lt;showWarnings&gt;true&lt;/showWarnings&gt;
                      &lt;verbose&gt;true&lt;/verbose&gt;
                      &lt;executable&gt;${jdk}/bin/javac&lt;/executable&gt;
                      &lt;fork&gt;true&lt;/fork&gt;
                  &lt;/configuration&gt;
                  &lt;dependencies&gt;
                      &lt;dependency&gt;
                          &lt;groupId&gt;org.codehaus.groovy&lt;/groupId&gt;
                          &lt;artifactId&gt;groovy-eclipse-compiler&lt;/artifactId&gt;
                          &lt;version&gt;2.9.2-01&lt;/version&gt;
                      &lt;/dependency&gt;
                      &lt;dependency&gt;
                          &lt;groupId&gt;org.codehaus.groovy&lt;/groupId&gt;
                          &lt;artifactId&gt;groovy-eclipse-batch&lt;/artifactId&gt;
                          &lt;version&gt;2.4.3-01&lt;/version&gt;
                      &lt;/dependency&gt;
                      &lt;dependency&gt;
                          &lt;groupId&gt;junit&lt;/groupId&gt;
                          &lt;artifactId&gt;junit&lt;/artifactId&gt;
                          &lt;version&gt;4.11&lt;/version&gt;
                      &lt;/dependency&gt;
                  &lt;/dependencies&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
                  &lt;artifactId&gt;cobertura-maven-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.7&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;formats&gt;
                          &lt;format&gt;html&lt;/format&gt;
                          &lt;format&gt;xml&lt;/format&gt;
                      &lt;/formats&gt;
                      &lt;outputDirectory&gt;${project.build.directory}/surefire-reports/cobertura&lt;/outputDirectory&gt;
                      &lt;instrumentation&gt;
                          &lt;ignoreTrivial&gt;true&lt;/ignoreTrivial&gt;
                          &lt;ignores&gt;
                              &lt;ignore&gt;org.slf4j.Logger.*&lt;/ignore&gt;
                          &lt;/ignores&gt;
                          &lt;excludes&gt;
                              &lt;exclude&gt;**/Application.class&lt;/exclude&gt;
                              &lt;exclude&gt;**/ApplicationConfig.class&lt;/exclude&gt;
                              &lt;exclude&gt;**/JerseyConfig.class&lt;/exclude&gt;
                          &lt;/excludes&gt;
                      &lt;/instrumentation&gt;
                      &lt;check /&gt;
                  &lt;/configuration&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;phase&gt;package&lt;/phase&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;cobertura&lt;/goal&gt;
                          &lt;/goals&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
      &lt;modules&gt;
          &lt;module&gt;model&lt;/module&gt;
          &lt;module&gt;persistence&lt;/module&gt;
          &lt;module&gt;service&lt;/module&gt;
      &lt;/modules&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>And the pom in the module looks like:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;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"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;groupId&gt;com.example&lt;/groupId&gt;
      &lt;artifactId&gt;model&lt;/artifactId&gt;
      &lt;name&gt;model&lt;/name&gt;
      &lt;description&gt;Model forservices&lt;/description&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt;
  
      &lt;parent&gt;
          &lt;artifactId&gt;parent&lt;/artifactId&gt;
          &lt;groupId&gt;com.example&lt;/groupId&gt;
          &lt;version&gt;1.0.0-SNAPSHOT&lt;/version&gt;
          &lt;relativePath&gt;../pom.xml&lt;/relativePath&gt;
      &lt;/parent&gt;
  
      &lt;properties&gt;
          &lt;java.version&gt;1.7&lt;/java.version&gt;
          &lt;java.source.version&gt;${java.version}&lt;/java.source.version&gt;
          &lt;java.target.version&gt;${java.version}&lt;/java.target.version&gt;
          &lt;jdk.version&gt;7&lt;/jdk.version&gt;
          &lt;jdk&gt;${env.JAVA_HOME_7}&lt;/jdk&gt;
      &lt;/properties&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.raml.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;raml-jaxrs-maven-plugin&lt;/artifactId&gt;
                  &lt;version&gt;1.3.3&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;jaxrsVersion&gt;2.0&lt;/jaxrsVersion&gt;
                      &lt;jsonMapper&gt;jackson2&lt;/jsonMapper&gt;
                      &lt;jsonMapperConfiguration&gt;
                          &lt;generateBuilders&gt;true&lt;/generateBuilders&gt;
                          &lt;includeHashcodeAndEquals&gt;true&lt;/includeHashcodeAndEquals&gt;
                          &lt;includeToStringuseLongIntegers&gt;true&lt;/includeToStringuseLongIntegers&gt;
                      &lt;/jsonMapperConfiguration&gt;
                  &lt;/configuration&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;id&gt;generate-model&lt;/id&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;generate&lt;/goal&gt;
                          &lt;/goals&gt;
                          &lt;phase&gt;generate-sources&lt;/phase&gt;
                          &lt;configuration&gt;
                              &lt;sourcePaths&gt;
                                  &lt;sourcePath&gt;${basedir}/src/main/raml/services.raml&lt;/sourcePath&gt;
                              &lt;/sourcePaths&gt;
                              &lt;basePackageName&gt;com.example.app&lt;/basePackageName&gt;
                          &lt;/configuration&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>However on compilation I get the following error:</p>
  
  <pre><code>[INFO] Found location &lt;/Users/someuser/.m2/repository/org/codehaus/groovy/groovy-eclipse-batch/2.4.3-01/groovy-eclipse-batch-2.4.3-01.jar&gt; for className &lt;org.eclipse.jdt.internal.compiler.batch.Main&gt;
  [INFO] no javaAgentClass seems to be set
  [INFO] Compiling in a forked process using /Users/someuser/.m2/repository/org/codehaus/groovy/groovy-eclipse-batch/2.4.3-01/groovy-eclipse-batch-2.4.3-01.jar
  [INFO] -------------------------------------------------------------
  [ERROR] COMPILATION ERROR : 
  [INFO] -------------------------------------------------------------
  [ERROR] Failure executing groovy-eclipse compiler:
  javac: invalid flag: -jar
  Usage: javac &lt;options&gt; &lt;source files&gt;
  use -help for a list of possible options
  
  [INFO] 1 error
  [INFO] -------------------------------------------------------------
  [INFO] ------------------------------------------------------------------------
  [INFO] BUILD FAILURE
  [INFO] ------------------------------------------------------------------------
  [INFO] Total time: 2.687s
  [INFO] Finished at: Thu May 26 10:04:15 EDT 2016
  [INFO] Final Memory: 21M/320M
  [INFO] ------------------------------------------------------------------------
  [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.3:compile (default-compile) on project model: Compilation failure
  [ERROR] Failure executing groovy-eclipse compiler:
  [ERROR] javac: invalid flag: -jar
  [ERROR] Usage: javac &lt;options&gt; &lt;source files&gt;
  [ERROR] use -help for a list of possible options
  </code></pre>
  
  <p>EDIT::</p>
  
  <p>So based on A. Di Matteo answer I tried</p>
  
  <ol>
  <li>removing the fork and executable options from the config section of the maven-compiler-plugin</li>
  <li>Setting the source and target version to 1.7 on my module that needed a different version of java</li>
  </ol>
  
  <p>It builds successfully. But when I read the build manifest it says Build-Jdk: 1.8.0_40. So what does that mean</p>
  
  <pre><code>Manifest-Version: 1.0
  Implementation-Title: model
  Build-Date: 2016-05-26 10:44:16
  Implementation-Version: 1.0.0-SNAPSHOT
  Archiver-Version: Plexus Archiver
  Built-By: 
  Specification-Vendor: my org
  Repo-Name: model
  Specification-Title: model
  Implementation-Vendor-Id: com.org
  Git-Hash: xxx
  Implementation-Vendor: my org
  App-Name: model
  Version-Number: 1.0.0-SNAPSHOT
  Created-By: Apache Maven 3.0.5
  Build-Jdk: 1.8.0_40
  Specification-Version: 1.0.0-SNAPSHOT
  </code></pre>