1

I am using spring-boot-maven-plugin to maven compile my source code as I want maven dependency jars to be part of my jar. (suggested by someone). I have written code according to java 1.7 but maven compiler is trying to compile it with 1.5 (default for maven). To change it I defined source as 1.7 but it is still compiling it with 1.5 Here is my pom.xml example.

<build>
    <sourceDirectory>src</sourceDirectory>
    <pluginManagement>
    <plugins>
    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <version>1.5.2.RELEASE</version>
        <configuration>
            <finalName>BAU_Report</finalName>
            <source>1.7</source>
            <target>1.7</target>
        </configuration>
        <executions>
            <execution>
                <goals>
                    <goal>repackage</goal>
                </goals>
                <configuration>
                  <transformers>
                     <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                     <mainClass>com.bau.report.MainClass</mainClass>
                 </transformer>
                 </transformers>
             </configuration>
         </execution>
        </executions>

      </plugin>
      </plugins>
    </pluginManagement>
  </build>

3 Answers3

1

You should use maven compiler plugin

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.7.0</version>
    <configuration>
      <source>1.7</source>
      <target>1.7</target>
    </configuration>
  </plugin>

Add this to build -> plugins section.

lakshman
  • 2,641
  • 6
  • 37
  • 63
  • after adding this I start getting "no main manifest attribute, in BAU_Report_VFIE-0.0.1-SNAPSHOT.jar" although I have mentioned my main class in spring boot plugin – Manish Rajput Apr 06 '18 at 10:00
  • @ManishRajput: Did you check the answers in this question for `no main manifest attribute` https://stackoverflow.com/questions/9689793/cant-execute-jar-file-no-main-manifest-attribute/15161904 – lakshman Apr 06 '18 at 10:13
  • how do you build and run the appilcation? what commands are using? – lakshman Apr 06 '18 at 10:23
  • Put maven assembly plugin and specify main class in build section as specified https://stackoverflow.com/questions/574594/how-can-i-create-an-executable-jar-with-dependencies-using-maven?noredirect=1&lq=1 – lakshman Apr 06 '18 at 10:33
  • In another way you should be able to run the jar file as `java -cp BAU_Report_VFIE-0.0.1-SNAPSHOT.jar com.bau.report.MainClass` – lakshman Apr 06 '18 at 10:42
0

Add org.apache.maven.plugins for the pom.xml file.

<build>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
    </plugin>
</build>

Maven properties for the compiler version can be set as following.

Method 1

<properties>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
</properties>
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

Method 2

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
    </plugins>
</build>
Saveendra Ekanayake
  • 3,153
  • 6
  • 34
  • 44
0

If you’re using the spring boot parent pom you can use this property shortcut instead in your pom.xml

<properties>
    <java.version>7</java.version>
</properties>
mekazu
  • 2,545
  • 3
  • 23
  • 21