Default files and values for Java 8 Maven Project

Recently, I often have to create new Java projects. Therefore, in order not to copy the same values from project to project, it was decided to write the common values in a separate post.


Let’s touch Java 8, Maven, Git.

pom.xml

In Maven, it is always necessary to specify the Java version, source files encoding, and report encoding. It’s possible to declare everything above in properties:

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <maven.compiler.source>${java.version}</maven.compiler.source>
        <maven.compiler.target>${java.version}</maven.compiler.target>
    </properties>

In the example above, we are forcing Maven to use Java 8 during compilation and UTF-8 encoding for both source and reporting.

.gitattributes

We want to have all the text files with Unix-style line endings (LF):

* text=auto

*.java text
*.properties text

.gitignore

Telling Git to ignore IntelliJ project files and Maven build directory:

*.iml
.idea/

**/target/