The project object model pom.xml

Figure 637. «Hello, world» pom.xml Slide presentation
<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/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>
  <groupId>de.hdm_stuttgart.mi</groupId>
  <artifactId>first</artifactId>
  <version>0.9</version>

</project>

Figure 638. Executing «compile» phase Slide presentation
mkdir -p src/main/java 

vim src/main/java/Hello.java 

first> mvn compile ...
[WARNING] File encoding has not been set, using platform encoding UTF-8, 
    i.e. build is platform dependent! ...
[ERROR] error: Source option 5 is no longer supported.  Use 6 or later.
[ERROR] error: Target option 1.5 is no longer supported.  Use 1.6 or later.

Create an empty folder designated for hosting Java sources. See Figure 633, “Maven project layout ” for reference.

Create an executable «Hello,world ...» class:

public class Hello {

   public static void main(String[] args) {
      System.out.println("Hello!");
}

Ask Maven for execution of the «compile» phase.

We have not yet specified an encoding on project level. Thus two platforms using different encoding may provide different artifact outcomes.

The world has moved: Java 1.5 compilers are outdated.


Figure 639. Examining the Java version culprit Slide presentation
>mvn help:effective-pom

<project ...>
   ...
  <plugin>
    <artifactId>maven-compiler-plugin</artifactId> ...

> find ~/.m2/repository/ -name maven-compiler-plugin\* ...
       
>jar -xf ~/.m2/repository/org/apache/maven/plugins/maven-compiler-plugin/3.7.0/maven-compiler-plugin-3.7.0.jar
>cat META-INF/maven/plugin.xml
<encoding implementation="java.lang.String" default-value="${project.build.sourceEncoding}">${encoding}</encoding>
<source implementation="java.lang.String" default-value="1.5">${maven.compiler.source}</source>
<target implementation="java.lang.String" default-value="1.5">${maven.compiler.target}</target>

Figure 640. Resolving encoding / Java version issues Slide presentation
<project ... xsd/maven-4.0.0.xsd">
...
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties> ...
rm -rf ~/.m2/repository/
mvn compile;     find ~/.m2/repository/ -type f|wc -l
220

Figure 641. POM inheritance Slide presentation

Figure 642. The Super POM Slide presentation
jar -tf /usr/share/apache-maven-3.0.5/lib/maven-model-builder-3.0.5.jar

...
org/apache/maven/model/plugin/ReportingConverter.class
org/apache/maven/model/pom-4.0.0.xml
org/apache/maven/model/profile/activation/FileProfileActivator$1.class
...

Figure 643. pom-4.0.0.xml content Slide presentation
...                          <!-- Does this ring a (security related?) bell? -->
<repositories>
  <repository>
    <id>central</id>
    <name>Central Repository</name>
    <url>http://repo.maven.apache.org/maven2</url>
...
  <pluginRepositories>
    <pluginRepository>
      <id>central</id>
      <name>Central Repository</name>
      <url>http://repo.maven.apache.org/maven2</url>
...

Figure 644. Favour https in ~/.m2/settings.xml Slide presentation
<settings ... settings-1.0.0.xsd">

  <mirrors>
    <mirror>
      <id>central-secure</id>
      <mirrorOf>central</mirrorOf>
      <name>Maven Central: Favour https over http.</name>
      <url>https://repo.maven.apache.org/maven2</url>
    </mirror>
  </mirrors>
  ...

Figure 645. Resolving to effective pom.xml Slide presentation
first> mvn help:effective-pom
... Effective POMs, after inheritance, interpolation, and profiles are applied:

<project xmlns="http://maven.apache.org/POM/4.0.0" ...>
  <modelVersion>4.0.0</modelVersion>
...
      <plugin>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.3.2</version>
        <executions>
          <execution>
            <id>default-jar</id>
...