Maven Java Sürümü Vermek

Projelerimizi yazarken yeni java sürümü özellikleri kullanmak istiyebiliriz. Eğer maven dosyamızı bu sürüm ile güncellemezsek, maven bize hata vericektir. Kullandığımız IDE yazdığımız kodun bir sonraki java sürümünü kullandığını düşünebilir bazı durumlarda ise maven dosyasında ileri bir java sürümünü yazsak bile IDE eski bir java sürümünde yazıyormuşuz gibi davranabilmektedir bu yüzden pom dosyamız içerisinde yer alan sürümün kullandığımız ide’de sorun yaratmamasına dikkat etmeliyiz.​

Pom.xml Dosyamıza Eklenecek
<properties>
      <maven.compiler.source>11</maven.compiler.source>
      <maven.compiler.target>11</maven.compiler.target>
</properties>

Eklediğimiz bu kod yardımıyla maven projemizi java 11 özellikleriyle kullanabilmekteyiz. Java 8 kullanmak istiyorsak 11 yerine 1.8 yapmamız gerekmekte.

Pom.xml En Son Hali
<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.dogukanhan.mvnexample1</groupId>
  <artifactId>maven-example2</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>maven-example2</name>
  <url>http://maven.apache.org</url>
  <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
  </properties>  
  <dependencies>
      <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
      </dependency>
    </dependencies>
</project>

 

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *