В Maven вы можете указать уровень языка с помощью maven-compiler-pluginв файле pom.xmlвашего проекта. Вот несколько способов установить уровень языка в Maven:
-
Укажите уровень языка в конфигурации
maven-compiler-plugin:<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <source>1.8</source> <!-- Set the desired language level --> <target>1.8</target> <!-- Set the desired target level --> </configuration> </plugin> </plugins> </build> -
Используйте свойства Maven, чтобы определить уровень языка:
<properties> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> </properties> -
Установите уровень языка с помощью параметров командной строки:
mvn clean install -Dmaven.compiler.source=1.8 -Dmaven.compiler.target=1.8 -
Используйте определенный профиль версии Java в вашем
pom.xml:<profiles> <profile> <id>java8</id> <activation> <jdk>[1.8,)</jdk> </activation> <properties> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> </properties> </profile> </profiles>Вы можете активировать этот профиль, используя параметр
-P, за которым следует идентификатор профиля:mvn clean install -Pjava8.