How to change java version in Maven compiler? Not for a specific project in the POM file, but in the Maven settings? I have the variables "JAVA_HOME" and "MAVEN_HOME". The current version of JAVA SDK is 9.0.4.

enter image description here

When I try to install a local library, I get the error "Source option 1.5 is no longer supported. Use 1.6 or later." enter image description here

  • one
    in properties add <maven.compiler.source>1.6</maven.compiler.source> - Senior Pomidor
  • @SeniorPomidor and where exactly to add it? - Ponomarenko Oleh
  • <project> .... <properties> in pom.xml file - Senior Pomidor
  • So I do not have a POM file, I wrote in the subject line: "Not for a specific project in the POM file, but in the Maven settings?" - Ponomarenko Oleh

2 answers 2

In the home folder there is a hidden folder .m2 . It is designed to store the local maven repository and global settings (they are needed). The settings are in $HOME/.m2/settings.xml There are already some settings there, most likely a profile. Below it says what properties you need to add to the active profile:

 <settings> <profiles> <profile> <id>...</id> <properties> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> </properties> </profile> </profiles> ... 

Settings from settings.xml are valid by default. So if in future projects you do not specify these settings, the version values ​​will be picked up from settings.xml

    it is possible to specify versions in pom

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

    You can add arguments during the mvn command.

     -Dmaven.compiler.source=1.6 -Dmaven.compiler.target=1.6 

    You can also open the maven / bin / mvn.bat file and add these arguments after

     ".../bin/mvn -Dmaven.compiler.source=1.6 -Dmaven.compiler.target=1.6" "$@" 

    then you will always have these versions and do not need to be passed in the startup parameters and added to pom

    • Pom? if this is a POM project file, I told you that this is not for a specific project, but for the compiler - Ponomarenko Oleh
    • updated answer. take a look - Senior Pomidor