Rabobank Ontwikkelprogramma
OPS Engineers
Bert Koorengevel – maart 2018
Building Java applications
with Apache Maven
https://karussell.wordpress.com/2009/09/29/
Staging
UFT
Continuous Integration
(build)
Continuous Delivery
(zero-touch deploy)
+
= CI-CD
Staging
Production
Apache Maven
• Apache Software Foundation:
community for Open Source software projects
• Maven: aYiddish word meaning
“accumulator of knowledge”
• Dominant build tool in the Java world
• Multi-platform (Windows / Unix),
command-line interface
Objectives
• Making the build process easy
• Providing a uniform build system
• Providing quality project information
• Providing guidelines for best practices development
• Allowing transparent migration to new features
Maven Installatie
• Prerequisites:
• JDK minimaal v1.7 (env.var %JAVA_HOME%)
• Download de .zip van https://maven.apache.org/download.cgi
• Eén distributie voor alle platforms (bevat zowel .bat als .sh scripts)
• Uitpakken naar bv c:appsmaven (nieuwe folder, full control)
• Voeg c:appsmavenbin toe aan je %PATH%
• Test op commandline:
• mvn -v
Extra configuratie voor RaboVDI’s
• Edit bestand [maven_home]confsettings.xml en pas het
<mirrors> gedeelte als volgt aan:
Maven is Modulair
• Alleen de core is nodig voor installatie (~2 Mb)
• Maven werkt verder (bijna) volledig met plugins
• Plugins en dependencies worden automatisch gedownload wanneer ze nodig zijn
• Deze afhankelijkheden worden in de user directory neergezet:
• ~/.m2 op linux / unix
• %HOMEPATH%/.m2 op windows
• Meerdere versies van plugins en dependencies kunnen naast elkaar bestaan
My First Maven project
• Execute:
• mvn archetype:generate -DgroupId=nl.ordina -DartifactId=MyFirstPony
• Plugins etc. worden gedownload
• Nieuwe projectfolder MyFirstPony
wordt gemaakt met daarin:
• Standaard folder structuur
met 2 java classes
• Een pom.xml
Maven process flow
‘Target’ folderMaven‘Source’ folder
pom.xml
WTF is an
Artifact?
• General definition: “any object made by human beings”
• In software: an application, module or component, typically archived (e.g. zip file)
• Storage in a Repository
• artifactId – identifier / name of the artefict
• groupId – serves as Namespace, so the artifactId need not be worldwide unique
• version – artifact versions are frozen. New build  increase version!
• Path in repository: / groupId / artifactId / version / artifactId-version.ext
What is an Artifact?
SportsQuestordina.nl.ordina.nl.ordina.jtech. -1.2.3nl.ordina.jtech.sportsquest./nl/ordina/jtech/sportsquest/ /1.2.3/SportsQuest-1.2.3.zip
Version: 1
• Major version
• Minor version
• Incremental version
• Build number
• or Qualifier
.2.3-45-SNAPSHOT
Structure of Maven artifactVersion
Local Maven Instance
Local Maven
Repository
Maven Repositories
get (artifact)
Artifact
Maven Central
Repository
get (artifact)
Artifact
Local Maven Instance
Local Maven
Repository
Maven Repositories
Maven Central
Repository
Corporate
Central
Repository
(Nexus)
Proxy
http://repo1.maven.org/maven2/http://maven.rabobank.nl/nexus
Firewall
Build Server
BuildServer
Repository
(Artifactory)
https://lrv142za/artifactory/C:MavenRepo
Maven – pom.xml
• pom = Project Object Model
• Controls the what and how of the build proces
• What: groupId, artifactId, version,
packaging :
• jar = Java ARchive
• war = Web application ARchive
• ear = Java Enterprise ARchive
• pom = other (produces only the pom.xml) or controlling multi-module builds
• How: we’ll see later, controlled in principle by packaging and plugins
• “Convention over Configuration” : sticking to the conventions reduces configuration
• Convention: the pom.xml is located in the root folder of the project
<?xml>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>nl.ordina.jtech</groupId>
<artifactId>MavenDemo</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
</project>
3 separate lifecycles:
• Clean : discard previous built files (workspace)
• Default : compilation & deployment (Maven repository)
• Site : generation of html reports (code quality, etc)
Maven Build Lifecycle
Each lifecycle consists of phases.
Most important phases of the default lifecycle:
• Compile
• Test
• Package
• Validate
• Install
• Deploy
Maven Build Lifecycle Phases
My First Maven Project Build
• Execute:
• cd MyFirstPony
• mvn install
• mvn package
• mvn clean package
En zoek de verschillen…
• clean
----------------------------------------------------------------------
| | /| /  / |¯¯¯ | | /¯¯ ¯¯|¯¯ / |¯¯ ¯¯|¯¯ |
| |  / | /__  / |-- |  | ¯¯ | /__ |--/ | |
| | / | /  / |___ | | __/ | /  |  | |
----------------------------------------------------------------------
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building MavenDemo 0.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ MavenDemo ---
[INFO] Deleting C:WorkspaceMavenWorkshopMavenDemotarget
Convention:
Maven only touches the “target” folder
Slow-Motion …
• clean
• validate
• initialize
• generate-sources
• process-sources
• generate-resources
• process-resources
----------------------------------------------------------------------
| | /| /  / |¯¯¯ | | /¯¯ ¯¯|¯¯ / |¯¯ ¯¯|¯¯ |
| |  / | /__  / |-- |  | ¯¯ | /__ |--/ | |
| | / | /  / |___ | | __/ | /  |  | |
----------------------------------------------------------------------
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building MavenDemo 0.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ MavenDemo ---
[INFO] Deleting C:WorkspaceMavenWorkshopMavenDemotarget
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ MavenDemo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
Conventions:
Output goes to /target/classes
Resource files are in /src/main/resources
Slow-Motion …
• clean
• validate
• initialize
• generate-sources
• process-sources
• generate-resources
• process-resources
• compile
----------------------------------------------------------------------
| | /| /  / |¯¯¯ | | /¯¯ ¯¯|¯¯ / |¯¯ ¯¯|¯¯ |
| |  / | /__  / |-- |  | ¯¯ | /__ |--/ | |
| | / | /  / |___ | | __/ | /  |  | |
----------------------------------------------------------------------
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building MavenDemo 0.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ MavenDemo ---
[INFO] Deleting C:WorkspaceMavenWorkshopMavenDemotarget
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ MavenDemo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
----------------------------------------------------------------------
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building MavenDemo 0.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ MavenDemo ---
[INFO] Deleting C:WorkspaceMavenWorkshopMavenDemotarget
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ MavenDemo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ MavenDemo ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:WorkspaceMavenWorkshopMavenDemotargetclasses
Convention:
Java source files are in /src/main/java
Slow-Motion …
• clean
• validate
• initialize
• generate-sources
• process-sources
• generate-resources
• process-resources
• compile
• process-classes
• generate-test-sources
• process-test-sources
• generate-test-resources
• process-test-resources
----------------------------------------------------------------------
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building MavenDemo 0.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ MavenDemo ---
[INFO] Deleting C:WorkspaceMavenWorkshopMavenDemotarget
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ MavenDemo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ MavenDemo ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:WorkspaceMavenWorkshopMavenDemotargetclasses
[INFO] ------------------------------------------------------------------------
[INFO] Building MavenDemo 0.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ MavenDemo ---
[INFO] Deleting C:WorkspaceMavenWorkshopMavenDemotarget
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ MavenDemo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ MavenDemo ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:WorkspaceMavenWorkshopMavenDemotargetclasses
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ MavenDemo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
Convention:
Test output goes to /target/test-classes
Test resources are in /src/test/resources
Slow-Motion …
• clean
• validate
• initialize
• generate-sources
• process-sources
• generate-resources
• process-resources
• compile
• process-classes
• generate-test-sources
• process-test-sources
• generate-test-resources
• process-test-resources
• test-compile
[INFO] ------------------------------------------------------------------------
[INFO] Building MavenDemo 0.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ MavenDemo ---
[INFO] Deleting C:WorkspaceMavenWorkshopMavenDemotarget
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ MavenDemo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ MavenDemo ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:WorkspaceMavenWorkshopMavenDemotargetclasses
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ MavenDemo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ MavenDemo ---
[INFO] Deleting C:WorkspaceMavenWorkshopMavenDemotarget
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ MavenDemo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ MavenDemo ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:WorkspaceMavenWorkshopMavenDemotargetclasses
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ MavenDemo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ MavenDemo ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:WorkspaceMavenWorkshopMavenDemotargettest-classes
Convention:
Test sources are in /src/test/java
Slow-Motion …
• clean
• validate
• initialize
• generate-sources
• process-sources
• generate-resources
• process-resources
• compile
• process-classes
• generate-test-sources
• process-test-sources
• generate-test-resources
• process-test-resources
• test-compile
• process-test-classes
• test
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ MavenDemo ---
[INFO] Deleting C:WorkspaceMavenWorkshopMavenDemotarget
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ MavenDemo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ MavenDemo ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:WorkspaceMavenWorkshopMavenDemotargetclasses
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ MavenDemo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ MavenDemo ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:WorkspaceMavenWorkshopMavenDemotargettest-classes
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ MavenDemo ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:WorkspaceMavenWorkshopMavenDemotargettest-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ MavenDemo ---
[INFO] Surefire report directory: C:WorkspaceMavenWorkshopMavenDemotargetsurefire-
reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running HelloMavenTest
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.016 sec
Results :
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0
Slow-Motion …
• clean
• validate
• initialize
• generate-sources
• process-sources
• generate-resources
• process-resources
• compile
• process-classes
• generate-test-sources
• process-test-sources
• generate-test-resources
• process-test-resources
• test-compile
• process-test-classes
• test
• prepare-package
• package
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ MavenDemo ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:WorkspaceMavenWorkshopMavenDemotargettest-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ MavenDemo ---
[INFO] Surefire report directory: C:WorkspaceMavenWorkshopMavenDemotargetsurefire-
reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running HelloMavenTest
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.016 sec
Results :
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ MavenDemo ---
[INFO] Surefire report directory: C:WorkspaceMavenWorkshopMavenDemotargetsurefire-
reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running HelloMavenTest
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.016 sec
Results :
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ MavenDemo ---
[INFO] Building jar: C:WorkspaceMavenWorkshopMavenDemotargetMavenDemo-0.0.jar
Slow-Motion …
• clean
• validate
• initialize
• generate-sources
• process-sources
• generate-resources
• process-resources
• compile
• process-classes
• generate-test-sources
• process-test-sources
• generate-test-resources
• process-test-resources
• test-compile
• process-test-classes
• test
• prepare-package
• package
• pre-integration-test
• integration-test
• post-integration-test
• verify
• install
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ MavenDemo ---
[INFO] Surefire report directory: C:WorkspaceMavenWorkshopMavenDemotargetsurefire-
reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running HelloMavenTest
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.016 sec
Results :
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ MavenDemo ---
[INFO] Building jar: C:WorkspaceMavenWorkshopMavenDemotargetMavenDemo-0.0.jar
T E S T S
-------------------------------------------------------
Running HelloMavenTest
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.016 sec
Results :
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ MavenDemo ---
[INFO] Building jar: C:WorkspaceMavenWorkshopMavenDemotargetMavenDemo-0.0.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ MavenDemo ---
[INFO] Installing C:WorkspaceMavenWorkshopMavenDemotargetMavenDemo-0.0.jar to
C:MavenReponlbertkoorMavenDemo0.0MavenDemo-0.0.jar
[INFO] Installing C:WorkspaceMavenWorkshopMavenDemopom.xml to
C:MavenReponlbertkoorMavenDemo0.0MavenDemo-0.0.pom
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ MavenDemo ---
[INFO] Building jar: C:WorkspaceMavenWorkshopMavenDemotargetMavenDemo-0.0.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ MavenDemo ---
[INFO] Installing C:WorkspaceMavenWorkshopMavenDemotargetMavenDemo-0.0.jar to
C:MavenReponlbertkoorMavenDemo0.0MavenDemo-0.0.jar
[INFO] Installing C:WorkspaceMavenWorkshopMavenDemopom.xml to
C:MavenReponlbertkoorMavenDemo0.0MavenDemo-0.0.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.028 s
[INFO] Finished at: 2016-01-20T10:45:32+01:00
[INFO] Final Memory: 16M/159M
[INFO] ------------------------------------------------------------------------
Slow-Motion …
• clean
• validate
• initialize
• generate-sources
• process-sources
• generate-resources
• process-resources
• compile
• process-classes
• generate-test-sources
• process-test-sources
• generate-test-resources
• process-test-resources
• test-compile
• process-test-classes
• test
• prepare-package
• package
• pre-integration-test
• integration-test
• post-integration-test
• verify
• install
• deploy
T E S T S
-------------------------------------------------------
Running HelloMavenTest
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.016 sec
Results :
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ MavenDemo ---
[INFO] Building jar: C:WorkspaceMavenWorkshopMavenDemotargetMavenDemo-0.0.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ MavenDemo ---
[INFO] Installing C:WorkspaceMavenWorkshopMavenDemotargetMavenDemo-0.0.jar to
C:MavenReponlbertkoorMavenDemo0.0MavenDemo-0.0.jar
[INFO] Installing C:WorkspaceMavenWorkshopMavenDemopom.xml to
C:MavenReponlbertkoorMavenDemo0.0MavenDemo-0.0.pom
[INFO] Installing C:WorkspaceMavenWorkshopMavenDemotargetMavenDemo-0.0.jar to
C:MavenReponlbertkoorMavenDemo0.0MavenDemo-0.0.jar
[INFO] Installing C:WorkspaceMavenWorkshopMavenDemopom.xml to
C:MavenReponlbertkoorMavenDemo0.0MavenDemo-0.0.pom
[INFO]
[INFO] --- maven-deploy-plugin:2.7:deploy (default-deploy) @ MavenDemo ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.232 s
[INFO] Finished at: 2016-01-20T10:41:10+01:00
[INFO] Final Memory: 16M/157M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy
(default-deploy) on project MavenDemo: Deployment failed: repository element was not
specified in the POM inside distributionManagement element or in -
DaltDeploymentRepository=id::layout::url parameter -> [Help 1]
“mvn clean install” suffices“mvn clean package” suffices
Slow-Motion …
Some Maven Conventions
• Maven only touches the “target” folder
• Locations:
• Java sources: /src/main/java
• Resources: /src/main/resources
• Output: /target/classes
• Test sources: /src/test/java
• Test resources: /src/test/resources
• Test output: /target/test-classes
Maven commandline
Tot nu toe gezien:
• mvn –v
• mvn archetype:generate -DartifactId=MyFirstPony
• mvn package
• mvn clean package
Algemeen formaat:
• mvn [ phase | pluginId:goal | -options ] ...
• mvn [groupId:]pluginId[:version]:goal
impliciet groupId org.apache.maven en maven-{pluginId}-plugin
Maven Build Failures
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project
MavenDemo: Deployment failed: repository element was not specified in the POM inside distributionManagement element
or in -DaltDeploymentRepository=id::layout::url parameter -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
c:WorkspaceMavenWorkshopMavenDemo> _
• mvn […] -e
Maven Build Failures
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project
MavenDemo: Deployment failed: repository element was not specified in the POM inside distributionManagement element
or in -DaltDeploymentRepository=id::layout::url parameter -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
c:WorkspaceMavenWorkshopMavenDemo> _
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project MavenDemo:
Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -
DaltDeploymentRepository=id::layout::url parameter -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-deploy-
plugin:2.7:deploy (default-deploy) on project MavenDemo: Deploy
ment failed: repository element was not specified in the POM inside distributionManagement element or in -
DaltDeploymentRepository=id::layout::url parameter
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:862)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:286)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:197)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: Deployment failed: repository element was not specified in the POM
inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter
at org.apache.maven.plugin.deploy.DeployMojo.getDeploymentRepository(DeployMojo.java:235)
at org.apache.maven.plugin.deploy.DeployMojo.execute(DeployMojo.java:118)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
... 20 more
• mvn […] -e
• mvn […] -X
Maven Build Failures
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project
MavenDemo: Deployment failed: repository element was not specified in the POM inside distributionManagement element
or in -DaltDeploymentRepository=id::layout::url parameter -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
c:WorkspaceMavenWorkshopMavenDemo> _
[INFO] Scanning for projects...
[DEBUG] Extension realms for project nl.bertkoor:MavenDemo:jar:0.0: (none)
[DEBUG] Looking up lifecyle mappings for packaging jar from ClassRealm[plexus.core, parent: null]
[DEBUG] === REACTOR BUILD PLAN ================================================
[DEBUG] Project: nl.bertkoor:MavenDemo:jar:0.0
[DEBUG] Tasks: [validate]
[DEBUG] Style: Regular
[DEBUG] =======================================================================
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building MavenDemo 0.0
[INFO] ------------------------------------------------------------------------
[DEBUG] Lifecycle default -> [validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes,
generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-
package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy]
[DEBUG] Lifecycle clean -> [pre-clean, clean, post-clean]
[DEBUG] Lifecycle site -> [pre-site, site, post-site, site-deploy]
[DEBUG] Lifecycle default -> [validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes,
generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-
package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy]
[DEBUG] Lifecycle clean -> [pre-clean, clean, post-clean]
[DEBUG] Lifecycle site -> [pre-site, site, post-site, site-deploy]
[DEBUG] === PROJECT BUILD PLAN ================================================
[DEBUG] Project: nl.bertkoor:MavenDemo:0.0
[DEBUG] Dependencies (collect): []
[DEBUG] Dependencies (resolve): [test]
[DEBUG] Repositories (dependencies): [central (https://lrv142za.europe.intranet/artifactory/libs-release, default, releases)]
[DEBUG] Repositories (plugins) : [central (https://lrv142za.europe.intranet/artifactory/plugins-release, default, releases)]
[DEBUG] -----------------------------------------------------------------------
[DEBUG] Goal: org.apache.maven.plugins:maven-antrun-plugin:1.6:run (default)
[DEBUG] Style: Regular
[DEBUG] Configuration: <?xml version="1.0" encoding="UTF-8"?>
<configuration>
<localRepository>${localRepository}</localRepository>
<pluginArtifacts>${plugin.artifacts}</pluginArtifacts>
<project>${project}</project>
<sourceRoot>${sourceRoot}</sourceRoot>
<target name="ant-step01">
<echo>Hello Maven!</echo>
</target>
<testSourceRoot>${testSourceRoot}</testSourceRoot>
<versionsPropertyName default-value="maven.project.dependencies.versions"/>
</configuration>
• mvn […] -e
• mvn […] -X
• http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Maven Build Failures
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project
MavenDemo: Deployment failed: repository element was not specified in the POM inside distributionManagement element
or in -DaltDeploymentRepository=id::layout::url parameter -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
c:WorkspaceMavenWorkshopMavenDemo> _
Maven Build Failures
• mvn […] -e
• mvn […] -X
• http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
• Read the error message!
Maven Build Failures
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project
MavenDemo: Deployment failed: repository element was not specified in the POM inside distributionManagement element
or in -DaltDeploymentRepository=id::layout::url parameter -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
c:WorkspaceMavenWorkshopMavenDemo> _
My pom.xml:
Mystery…
<?xml>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>nl.ordina.jtech</groupId>
<artifactId>MavenDemo</artifactId>
<version>0.0</version>
</project>
[INFO] ------------------------------------------------------------------------
[INFO] Building MavenDemo 0.0
[INFO] ------------------------------------------------------------------------
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ MavenDemo ---
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ MavenDemo ---
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ MavenDemo ---
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ MavenDemo ---
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ MavenDemo ---
[INFO] --- maven-install-plugin:2.4:install (default-install) @ MavenDemo ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
Maven did:
<?xml>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>nl.ordina.jtech</groupId>
<artifactId>MavenDemo</artifactId>
<version>0.0</version>
</project>
[INFO] ------------------------------------------------------------------------
[INFO] Building MavenDemo 0.0
[INFO] ------------------------------------------------------------------------
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ MavenDemo ---
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ MavenDemo ---
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ MavenDemo ---
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ MavenDemo ---
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ MavenDemo ---
[INFO] --- maven-install-plugin:2.4:install (default-install) @ MavenDemo ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
Convention over configuration : “Super” pom
mvn help:effective-pom
Demystified: the ‘Effective’ pom
My pom.xml:
Maven did:
POM elements
• GroupId
• ArtifactId
• Version
• Packaging
• Name
• Description
• Mailinglists
• Developers
• SCM
• Modules
• Dependencies
• Build
• Plugins
• Properties
• Repositories
• CI Management
• Reports
• DistributionManagement
• IssueManagement
Packaging
• jar (default)
• war
• ejb
• ear
• pom
• maven-plugin
De packaging bepaalt welke phases er worden gebruikt en welke
standaard set van plugin goals er aan de phases gekoppeld zijn
Packaging experiment
• Voer uit in het MyLittlePony project
• mvn help:effective-pom –Doutput=eff_pom_jar.xml
• Verander de packaging in war
• Voer uit:
• mvn help:effective-pom –Doutput=eff_pom_war.xml
• Vergelijk de twee output bestanden
Properties
<project>
...
<description>My project ${myProperty}</description>
<properties>
<myProperty>has a value</myProperty>
</properties>
mvn [goals] –DmyProperty="has no value"
Dependencies
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
• Vastleggen van afhankelijkheden
met andere jars
• Scope is optioneel:
• compile (default)
• provided
• test
Transitive Dependencies
• MyProject dependencies:
• LibraryA-1.1.jar, which depends on
• LibraryB-1.1.jar
• LibraryC-1.4.jar, which depends on
• LibraryB-1.4.jar
• Inzichtelijk te maken met:
• mvn dependency:tree
• Op te lossen met <exclude>
DependencyManagement
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies>
• Declaratie van versie zonder de
afhankelijkheid vast te leggen
• Meestal in Parent pom’s,
uniformiteit over gehele project
Modules – aggregate build
• Elke module is een subdirectory
(kan afwijkend artifactId hebben)
met een eigen Maven project dat
ook moet worden gebouwd
• Parent die de modules bevat
heeft meestal packaging=pom
<modules>
<module>core</module>
<module>model</module>
<module>webservice</module>
</modules>
Plugins
• Toevoegen of aanpassen van gedrag
• Vaak ook via PluginManagement in de parent pom
Parent pom
• Bovenliggende folder
• Relative Path
• GroupId, artifactId & version (coordinaten)
c:MavenReponlbertkoorMavenDemo0.0> java -cp MavenDemo-0.0.jar HelloMaven
Hello Maven!
c:MavenReponlbertkoorMavenDemo0.0> java -cp MavenDemo-0.0.jar HelloMaven Bert
Hello Bert!
c:MavenReponlbertkoorMavenDemo0.0> java -jar MavenDemo-0.0.jar
no main manifest attribute, in MavenDemo-0.0.jar
c:MavenReponlbertkoorMavenDemo0.0> java -cp MavenDemo-0.0.jar HelloMaven
Hello Maven!
c:MavenReponlbertkoorMavenDemo0.0> java -cp MavenDemo-0.0.jar HelloMaven Bert
Hello Bert!
c:MavenReponlbertkoorMavenDemo0.0> java -jar MavenDemo-0.0.jar
no main manifest attribute, in MavenDemo-0.0.jar
C:WorkspaceMavenWorkshopMavenDemo> mvn clean install
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
c:MavenReponlbertkoorMavenDemo0.0> java -jar MavenDemo-0.0.jar
Hello Maven!
• maven-compiler-plugin
• maven-jar-plugin
• maven-resources-plugin
• maven-assembly-plugin
Meer info: https://maven.apache.org/plugins/index.html
Meest gebruikte plugins
Resources
• Folders src/main/resources en src/test/resources
• Onderliggende directory structuur wordt in .jar geplaatst
• maven-resources-plugin configuratie (o.a.)
• includes
• excludes
• Resource Filtering:
• Vervangt ${property} met z’n waarde
Profielen
Aanpassing van de build (ander plugin gedrag) op basis van activering:
• Standaard activering (activeByDefault)
• Command line activering
• parameter –PprofileName
• Property waarden
• JDK versie
• OS naam, familie, versie
• (niet) Bestaan van een bestand
Profiel definities
• In de pom.xml
• In de profiles.xml
• In de persoonlijke settings.xml
• In de maven config
• %MAVEN_HOME%/conf/settings.xml
Settings.xml
Locatie:
• %MavenHome%/conf/settings.xml
• %UserHome%/.m2/settings.xml
• In de project folder
Bevat:
• Repository locaties
• Proxy instellingen
• Mirrors
• Server access credentials
• Zie https://github.com/BertKoor/OefenMaven
In het diepe !!!

Development Tools - Maven

  • 1.
    Rabobank Ontwikkelprogramma OPS Engineers BertKoorengevel – maart 2018 Building Java applications with Apache Maven
  • 2.
  • 3.
  • 4.
    Apache Maven • ApacheSoftware Foundation: community for Open Source software projects • Maven: aYiddish word meaning “accumulator of knowledge” • Dominant build tool in the Java world • Multi-platform (Windows / Unix), command-line interface
  • 5.
    Objectives • Making thebuild process easy • Providing a uniform build system • Providing quality project information • Providing guidelines for best practices development • Allowing transparent migration to new features
  • 6.
    Maven Installatie • Prerequisites: •JDK minimaal v1.7 (env.var %JAVA_HOME%) • Download de .zip van https://maven.apache.org/download.cgi • Eén distributie voor alle platforms (bevat zowel .bat als .sh scripts) • Uitpakken naar bv c:appsmaven (nieuwe folder, full control) • Voeg c:appsmavenbin toe aan je %PATH% • Test op commandline: • mvn -v
  • 7.
    Extra configuratie voorRaboVDI’s • Edit bestand [maven_home]confsettings.xml en pas het <mirrors> gedeelte als volgt aan:
  • 8.
    Maven is Modulair •Alleen de core is nodig voor installatie (~2 Mb) • Maven werkt verder (bijna) volledig met plugins • Plugins en dependencies worden automatisch gedownload wanneer ze nodig zijn • Deze afhankelijkheden worden in de user directory neergezet: • ~/.m2 op linux / unix • %HOMEPATH%/.m2 op windows • Meerdere versies van plugins en dependencies kunnen naast elkaar bestaan
  • 9.
    My First Mavenproject • Execute: • mvn archetype:generate -DgroupId=nl.ordina -DartifactId=MyFirstPony • Plugins etc. worden gedownload • Nieuwe projectfolder MyFirstPony wordt gemaakt met daarin: • Standaard folder structuur met 2 java classes • Een pom.xml
  • 10.
    Maven process flow ‘Target’folderMaven‘Source’ folder pom.xml
  • 11.
  • 14.
    • General definition:“any object made by human beings” • In software: an application, module or component, typically archived (e.g. zip file) • Storage in a Repository • artifactId – identifier / name of the artefict • groupId – serves as Namespace, so the artifactId need not be worldwide unique • version – artifact versions are frozen. New build  increase version! • Path in repository: / groupId / artifactId / version / artifactId-version.ext What is an Artifact? SportsQuestordina.nl.ordina.nl.ordina.jtech. -1.2.3nl.ordina.jtech.sportsquest./nl/ordina/jtech/sportsquest/ /1.2.3/SportsQuest-1.2.3.zip
  • 15.
    Version: 1 • Majorversion • Minor version • Incremental version • Build number • or Qualifier .2.3-45-SNAPSHOT Structure of Maven artifactVersion
  • 16.
    Local Maven Instance LocalMaven Repository Maven Repositories get (artifact) Artifact Maven Central Repository get (artifact) Artifact
  • 17.
    Local Maven Instance LocalMaven Repository Maven Repositories Maven Central Repository Corporate Central Repository (Nexus) Proxy http://repo1.maven.org/maven2/http://maven.rabobank.nl/nexus Firewall Build Server BuildServer Repository (Artifactory) https://lrv142za/artifactory/C:MavenRepo
  • 18.
    Maven – pom.xml •pom = Project Object Model • Controls the what and how of the build proces • What: groupId, artifactId, version, packaging : • jar = Java ARchive • war = Web application ARchive • ear = Java Enterprise ARchive • pom = other (produces only the pom.xml) or controlling multi-module builds • How: we’ll see later, controlled in principle by packaging and plugins • “Convention over Configuration” : sticking to the conventions reduces configuration • Convention: the pom.xml is located in the root folder of the project <?xml> <project> <modelVersion>4.0.0</modelVersion> <groupId>nl.ordina.jtech</groupId> <artifactId>MavenDemo</artifactId> <version>1.0</version> <packaging>jar</packaging> </project>
  • 19.
    3 separate lifecycles: •Clean : discard previous built files (workspace) • Default : compilation & deployment (Maven repository) • Site : generation of html reports (code quality, etc) Maven Build Lifecycle
  • 20.
    Each lifecycle consistsof phases. Most important phases of the default lifecycle: • Compile • Test • Package • Validate • Install • Deploy Maven Build Lifecycle Phases
  • 21.
    My First MavenProject Build • Execute: • cd MyFirstPony • mvn install • mvn package • mvn clean package En zoek de verschillen…
  • 22.
    • clean ---------------------------------------------------------------------- | |/| / / |¯¯¯ | | /¯¯ ¯¯|¯¯ / |¯¯ ¯¯|¯¯ | | | / | /__ / |-- | | ¯¯ | /__ |--/ | | | | / | / / |___ | | __/ | / | | | ---------------------------------------------------------------------- [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building MavenDemo 0.0 [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ MavenDemo --- [INFO] Deleting C:WorkspaceMavenWorkshopMavenDemotarget Convention: Maven only touches the “target” folder Slow-Motion …
  • 23.
    • clean • validate •initialize • generate-sources • process-sources • generate-resources • process-resources ---------------------------------------------------------------------- | | /| / / |¯¯¯ | | /¯¯ ¯¯|¯¯ / |¯¯ ¯¯|¯¯ | | | / | /__ / |-- | | ¯¯ | /__ |--/ | | | | / | / / |___ | | __/ | / | | | ---------------------------------------------------------------------- [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building MavenDemo 0.0 [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ MavenDemo --- [INFO] Deleting C:WorkspaceMavenWorkshopMavenDemotarget [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ MavenDemo --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 1 resource Conventions: Output goes to /target/classes Resource files are in /src/main/resources Slow-Motion …
  • 24.
    • clean • validate •initialize • generate-sources • process-sources • generate-resources • process-resources • compile ---------------------------------------------------------------------- | | /| / / |¯¯¯ | | /¯¯ ¯¯|¯¯ / |¯¯ ¯¯|¯¯ | | | / | /__ / |-- | | ¯¯ | /__ |--/ | | | | / | / / |___ | | __/ | / | | | ---------------------------------------------------------------------- [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building MavenDemo 0.0 [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ MavenDemo --- [INFO] Deleting C:WorkspaceMavenWorkshopMavenDemotarget [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ MavenDemo --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 1 resource ---------------------------------------------------------------------- [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building MavenDemo 0.0 [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ MavenDemo --- [INFO] Deleting C:WorkspaceMavenWorkshopMavenDemotarget [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ MavenDemo --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 1 resource [INFO] [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ MavenDemo --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 1 source file to C:WorkspaceMavenWorkshopMavenDemotargetclasses Convention: Java source files are in /src/main/java Slow-Motion …
  • 25.
    • clean • validate •initialize • generate-sources • process-sources • generate-resources • process-resources • compile • process-classes • generate-test-sources • process-test-sources • generate-test-resources • process-test-resources ---------------------------------------------------------------------- [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building MavenDemo 0.0 [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ MavenDemo --- [INFO] Deleting C:WorkspaceMavenWorkshopMavenDemotarget [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ MavenDemo --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 1 resource [INFO] [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ MavenDemo --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 1 source file to C:WorkspaceMavenWorkshopMavenDemotargetclasses [INFO] ------------------------------------------------------------------------ [INFO] Building MavenDemo 0.0 [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ MavenDemo --- [INFO] Deleting C:WorkspaceMavenWorkshopMavenDemotarget [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ MavenDemo --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 1 resource [INFO] [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ MavenDemo --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 1 source file to C:WorkspaceMavenWorkshopMavenDemotargetclasses [INFO] [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ MavenDemo --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 1 resource Convention: Test output goes to /target/test-classes Test resources are in /src/test/resources Slow-Motion …
  • 26.
    • clean • validate •initialize • generate-sources • process-sources • generate-resources • process-resources • compile • process-classes • generate-test-sources • process-test-sources • generate-test-resources • process-test-resources • test-compile [INFO] ------------------------------------------------------------------------ [INFO] Building MavenDemo 0.0 [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ MavenDemo --- [INFO] Deleting C:WorkspaceMavenWorkshopMavenDemotarget [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ MavenDemo --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 1 resource [INFO] [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ MavenDemo --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 1 source file to C:WorkspaceMavenWorkshopMavenDemotargetclasses [INFO] [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ MavenDemo --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 1 resource [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ MavenDemo --- [INFO] Deleting C:WorkspaceMavenWorkshopMavenDemotarget [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ MavenDemo --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 1 resource [INFO] [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ MavenDemo --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 1 source file to C:WorkspaceMavenWorkshopMavenDemotargetclasses [INFO] [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ MavenDemo --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 1 resource [INFO] [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ MavenDemo --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 1 source file to C:WorkspaceMavenWorkshopMavenDemotargettest-classes Convention: Test sources are in /src/test/java Slow-Motion …
  • 27.
    • clean • validate •initialize • generate-sources • process-sources • generate-resources • process-resources • compile • process-classes • generate-test-sources • process-test-sources • generate-test-resources • process-test-resources • test-compile • process-test-classes • test [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ MavenDemo --- [INFO] Deleting C:WorkspaceMavenWorkshopMavenDemotarget [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ MavenDemo --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 1 resource [INFO] [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ MavenDemo --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 1 source file to C:WorkspaceMavenWorkshopMavenDemotargetclasses [INFO] [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ MavenDemo --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 1 resource [INFO] [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ MavenDemo --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 1 source file to C:WorkspaceMavenWorkshopMavenDemotargettest-classes [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ MavenDemo --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 1 source file to C:WorkspaceMavenWorkshopMavenDemotargettest-classes [INFO] [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ MavenDemo --- [INFO] Surefire report directory: C:WorkspaceMavenWorkshopMavenDemotargetsurefire- reports ------------------------------------------------------- T E S T S ------------------------------------------------------- Running HelloMavenTest Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.016 sec Results : Tests run: 4, Failures: 0, Errors: 0, Skipped: 0 Slow-Motion …
  • 28.
    • clean • validate •initialize • generate-sources • process-sources • generate-resources • process-resources • compile • process-classes • generate-test-sources • process-test-sources • generate-test-resources • process-test-resources • test-compile • process-test-classes • test • prepare-package • package [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ MavenDemo --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 1 source file to C:WorkspaceMavenWorkshopMavenDemotargettest-classes [INFO] [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ MavenDemo --- [INFO] Surefire report directory: C:WorkspaceMavenWorkshopMavenDemotargetsurefire- reports ------------------------------------------------------- T E S T S ------------------------------------------------------- Running HelloMavenTest Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.016 sec Results : Tests run: 4, Failures: 0, Errors: 0, Skipped: 0 [INFO] [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ MavenDemo --- [INFO] Surefire report directory: C:WorkspaceMavenWorkshopMavenDemotargetsurefire- reports ------------------------------------------------------- T E S T S ------------------------------------------------------- Running HelloMavenTest Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.016 sec Results : Tests run: 4, Failures: 0, Errors: 0, Skipped: 0 [INFO] [INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ MavenDemo --- [INFO] Building jar: C:WorkspaceMavenWorkshopMavenDemotargetMavenDemo-0.0.jar Slow-Motion …
  • 29.
    • clean • validate •initialize • generate-sources • process-sources • generate-resources • process-resources • compile • process-classes • generate-test-sources • process-test-sources • generate-test-resources • process-test-resources • test-compile • process-test-classes • test • prepare-package • package • pre-integration-test • integration-test • post-integration-test • verify • install [INFO] [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ MavenDemo --- [INFO] Surefire report directory: C:WorkspaceMavenWorkshopMavenDemotargetsurefire- reports ------------------------------------------------------- T E S T S ------------------------------------------------------- Running HelloMavenTest Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.016 sec Results : Tests run: 4, Failures: 0, Errors: 0, Skipped: 0 [INFO] [INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ MavenDemo --- [INFO] Building jar: C:WorkspaceMavenWorkshopMavenDemotargetMavenDemo-0.0.jar T E S T S ------------------------------------------------------- Running HelloMavenTest Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.016 sec Results : Tests run: 4, Failures: 0, Errors: 0, Skipped: 0 [INFO] [INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ MavenDemo --- [INFO] Building jar: C:WorkspaceMavenWorkshopMavenDemotargetMavenDemo-0.0.jar [INFO] [INFO] --- maven-install-plugin:2.4:install (default-install) @ MavenDemo --- [INFO] Installing C:WorkspaceMavenWorkshopMavenDemotargetMavenDemo-0.0.jar to C:MavenReponlbertkoorMavenDemo0.0MavenDemo-0.0.jar [INFO] Installing C:WorkspaceMavenWorkshopMavenDemopom.xml to C:MavenReponlbertkoorMavenDemo0.0MavenDemo-0.0.pom Tests run: 4, Failures: 0, Errors: 0, Skipped: 0 [INFO] [INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ MavenDemo --- [INFO] Building jar: C:WorkspaceMavenWorkshopMavenDemotargetMavenDemo-0.0.jar [INFO] [INFO] --- maven-install-plugin:2.4:install (default-install) @ MavenDemo --- [INFO] Installing C:WorkspaceMavenWorkshopMavenDemotargetMavenDemo-0.0.jar to C:MavenReponlbertkoorMavenDemo0.0MavenDemo-0.0.jar [INFO] Installing C:WorkspaceMavenWorkshopMavenDemopom.xml to C:MavenReponlbertkoorMavenDemo0.0MavenDemo-0.0.pom [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 4.028 s [INFO] Finished at: 2016-01-20T10:45:32+01:00 [INFO] Final Memory: 16M/159M [INFO] ------------------------------------------------------------------------ Slow-Motion …
  • 30.
    • clean • validate •initialize • generate-sources • process-sources • generate-resources • process-resources • compile • process-classes • generate-test-sources • process-test-sources • generate-test-resources • process-test-resources • test-compile • process-test-classes • test • prepare-package • package • pre-integration-test • integration-test • post-integration-test • verify • install • deploy T E S T S ------------------------------------------------------- Running HelloMavenTest Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.016 sec Results : Tests run: 4, Failures: 0, Errors: 0, Skipped: 0 [INFO] [INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ MavenDemo --- [INFO] Building jar: C:WorkspaceMavenWorkshopMavenDemotargetMavenDemo-0.0.jar [INFO] [INFO] --- maven-install-plugin:2.4:install (default-install) @ MavenDemo --- [INFO] Installing C:WorkspaceMavenWorkshopMavenDemotargetMavenDemo-0.0.jar to C:MavenReponlbertkoorMavenDemo0.0MavenDemo-0.0.jar [INFO] Installing C:WorkspaceMavenWorkshopMavenDemopom.xml to C:MavenReponlbertkoorMavenDemo0.0MavenDemo-0.0.pom [INFO] Installing C:WorkspaceMavenWorkshopMavenDemotargetMavenDemo-0.0.jar to C:MavenReponlbertkoorMavenDemo0.0MavenDemo-0.0.jar [INFO] Installing C:WorkspaceMavenWorkshopMavenDemopom.xml to C:MavenReponlbertkoorMavenDemo0.0MavenDemo-0.0.pom [INFO] [INFO] --- maven-deploy-plugin:2.7:deploy (default-deploy) @ MavenDemo --- [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 3.232 s [INFO] Finished at: 2016-01-20T10:41:10+01:00 [INFO] Final Memory: 16M/157M [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project MavenDemo: Deployment failed: repository element was not specified in the POM inside distributionManagement element or in - DaltDeploymentRepository=id::layout::url parameter -> [Help 1] “mvn clean install” suffices“mvn clean package” suffices Slow-Motion …
  • 31.
    Some Maven Conventions •Maven only touches the “target” folder • Locations: • Java sources: /src/main/java • Resources: /src/main/resources • Output: /target/classes • Test sources: /src/test/java • Test resources: /src/test/resources • Test output: /target/test-classes
  • 32.
    Maven commandline Tot nutoe gezien: • mvn –v • mvn archetype:generate -DartifactId=MyFirstPony • mvn package • mvn clean package Algemeen formaat: • mvn [ phase | pluginId:goal | -options ] ... • mvn [groupId:]pluginId[:version]:goal impliciet groupId org.apache.maven en maven-{pluginId}-plugin
  • 33.
    Maven Build Failures [INFO]------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project MavenDemo: Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException c:WorkspaceMavenWorkshopMavenDemo> _
  • 34.
    • mvn […]-e Maven Build Failures [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project MavenDemo: Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException c:WorkspaceMavenWorkshopMavenDemo> _ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project MavenDemo: Deployment failed: repository element was not specified in the POM inside distributionManagement element or in - DaltDeploymentRepository=id::layout::url parameter -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-deploy- plugin:2.7:deploy (default-deploy) on project MavenDemo: Deploy ment failed: repository element was not specified in the POM inside distributionManagement element or in - DaltDeploymentRepository=id::layout::url parameter at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106) at org.apache.maven.cli.MavenCli.execute(MavenCli.java:862) at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:286) at org.apache.maven.cli.MavenCli.main(MavenCli.java:197) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289) at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415) at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356) Caused by: org.apache.maven.plugin.MojoExecutionException: Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter at org.apache.maven.plugin.deploy.DeployMojo.getDeploymentRepository(DeployMojo.java:235) at org.apache.maven.plugin.deploy.DeployMojo.execute(DeployMojo.java:118) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208) ... 20 more
  • 35.
    • mvn […]-e • mvn […] -X Maven Build Failures [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project MavenDemo: Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException c:WorkspaceMavenWorkshopMavenDemo> _ [INFO] Scanning for projects... [DEBUG] Extension realms for project nl.bertkoor:MavenDemo:jar:0.0: (none) [DEBUG] Looking up lifecyle mappings for packaging jar from ClassRealm[plexus.core, parent: null] [DEBUG] === REACTOR BUILD PLAN ================================================ [DEBUG] Project: nl.bertkoor:MavenDemo:jar:0.0 [DEBUG] Tasks: [validate] [DEBUG] Style: Regular [DEBUG] ======================================================================= [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building MavenDemo 0.0 [INFO] ------------------------------------------------------------------------ [DEBUG] Lifecycle default -> [validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare- package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy] [DEBUG] Lifecycle clean -> [pre-clean, clean, post-clean] [DEBUG] Lifecycle site -> [pre-site, site, post-site, site-deploy] [DEBUG] Lifecycle default -> [validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare- package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy] [DEBUG] Lifecycle clean -> [pre-clean, clean, post-clean] [DEBUG] Lifecycle site -> [pre-site, site, post-site, site-deploy] [DEBUG] === PROJECT BUILD PLAN ================================================ [DEBUG] Project: nl.bertkoor:MavenDemo:0.0 [DEBUG] Dependencies (collect): [] [DEBUG] Dependencies (resolve): [test] [DEBUG] Repositories (dependencies): [central (https://lrv142za.europe.intranet/artifactory/libs-release, default, releases)] [DEBUG] Repositories (plugins) : [central (https://lrv142za.europe.intranet/artifactory/plugins-release, default, releases)] [DEBUG] ----------------------------------------------------------------------- [DEBUG] Goal: org.apache.maven.plugins:maven-antrun-plugin:1.6:run (default) [DEBUG] Style: Regular [DEBUG] Configuration: <?xml version="1.0" encoding="UTF-8"?> <configuration> <localRepository>${localRepository}</localRepository> <pluginArtifacts>${plugin.artifacts}</pluginArtifacts> <project>${project}</project> <sourceRoot>${sourceRoot}</sourceRoot> <target name="ant-step01"> <echo>Hello Maven!</echo> </target> <testSourceRoot>${testSourceRoot}</testSourceRoot> <versionsPropertyName default-value="maven.project.dependencies.versions"/> </configuration>
  • 36.
    • mvn […]-e • mvn […] -X • http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException Maven Build Failures [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project MavenDemo: Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException c:WorkspaceMavenWorkshopMavenDemo> _
  • 37.
  • 38.
    • mvn […]-e • mvn […] -X • http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException • Read the error message! Maven Build Failures [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project MavenDemo: Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException c:WorkspaceMavenWorkshopMavenDemo> _
  • 39.
    My pom.xml: Mystery… <?xml> <project> <modelVersion>4.0.0</modelVersion> <groupId>nl.ordina.jtech</groupId> <artifactId>MavenDemo</artifactId> <version>0.0</version> </project> [INFO] ------------------------------------------------------------------------ [INFO]Building MavenDemo 0.0 [INFO] ------------------------------------------------------------------------ [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ MavenDemo --- [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ MavenDemo --- [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ MavenDemo --- [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ MavenDemo --- [INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ MavenDemo --- [INFO] --- maven-install-plugin:2.4:install (default-install) @ MavenDemo --- [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ Maven did:
  • 40.
    <?xml> <project> <modelVersion>4.0.0</modelVersion> <groupId>nl.ordina.jtech</groupId> <artifactId>MavenDemo</artifactId> <version>0.0</version> </project> [INFO] ------------------------------------------------------------------------ [INFO] BuildingMavenDemo 0.0 [INFO] ------------------------------------------------------------------------ [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ MavenDemo --- [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ MavenDemo --- [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ MavenDemo --- [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ MavenDemo --- [INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ MavenDemo --- [INFO] --- maven-install-plugin:2.4:install (default-install) @ MavenDemo --- [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ Convention over configuration : “Super” pom mvn help:effective-pom Demystified: the ‘Effective’ pom My pom.xml: Maven did:
  • 41.
    POM elements • GroupId •ArtifactId • Version • Packaging • Name • Description • Mailinglists • Developers • SCM • Modules • Dependencies • Build • Plugins • Properties • Repositories • CI Management • Reports • DistributionManagement • IssueManagement
  • 42.
    Packaging • jar (default) •war • ejb • ear • pom • maven-plugin De packaging bepaalt welke phases er worden gebruikt en welke standaard set van plugin goals er aan de phases gekoppeld zijn
  • 43.
    Packaging experiment • Voeruit in het MyLittlePony project • mvn help:effective-pom –Doutput=eff_pom_jar.xml • Verander de packaging in war • Voer uit: • mvn help:effective-pom –Doutput=eff_pom_war.xml • Vergelijk de twee output bestanden
  • 44.
    Properties <project> ... <description>My project ${myProperty}</description> <properties> <myProperty>hasa value</myProperty> </properties> mvn [goals] –DmyProperty="has no value"
  • 45.
  • 46.
    Transitive Dependencies • MyProjectdependencies: • LibraryA-1.1.jar, which depends on • LibraryB-1.1.jar • LibraryC-1.4.jar, which depends on • LibraryB-1.4.jar • Inzichtelijk te maken met: • mvn dependency:tree • Op te lossen met <exclude>
  • 47.
  • 48.
    Modules – aggregatebuild • Elke module is een subdirectory (kan afwijkend artifactId hebben) met een eigen Maven project dat ook moet worden gebouwd • Parent die de modules bevat heeft meestal packaging=pom <modules> <module>core</module> <module>model</module> <module>webservice</module> </modules>
  • 49.
    Plugins • Toevoegen ofaanpassen van gedrag • Vaak ook via PluginManagement in de parent pom Parent pom • Bovenliggende folder • Relative Path • GroupId, artifactId & version (coordinaten)
  • 50.
    c:MavenReponlbertkoorMavenDemo0.0> java -cpMavenDemo-0.0.jar HelloMaven Hello Maven! c:MavenReponlbertkoorMavenDemo0.0> java -cp MavenDemo-0.0.jar HelloMaven Bert Hello Bert! c:MavenReponlbertkoorMavenDemo0.0> java -jar MavenDemo-0.0.jar no main manifest attribute, in MavenDemo-0.0.jar
  • 51.
    c:MavenReponlbertkoorMavenDemo0.0> java -cpMavenDemo-0.0.jar HelloMaven Hello Maven! c:MavenReponlbertkoorMavenDemo0.0> java -cp MavenDemo-0.0.jar HelloMaven Bert Hello Bert! c:MavenReponlbertkoorMavenDemo0.0> java -jar MavenDemo-0.0.jar no main manifest attribute, in MavenDemo-0.0.jar C:WorkspaceMavenWorkshopMavenDemo> mvn clean install [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ c:MavenReponlbertkoorMavenDemo0.0> java -jar MavenDemo-0.0.jar Hello Maven!
  • 52.
    • maven-compiler-plugin • maven-jar-plugin •maven-resources-plugin • maven-assembly-plugin Meer info: https://maven.apache.org/plugins/index.html Meest gebruikte plugins
  • 53.
    Resources • Folders src/main/resourcesen src/test/resources • Onderliggende directory structuur wordt in .jar geplaatst • maven-resources-plugin configuratie (o.a.) • includes • excludes • Resource Filtering: • Vervangt ${property} met z’n waarde
  • 54.
    Profielen Aanpassing van debuild (ander plugin gedrag) op basis van activering: • Standaard activering (activeByDefault) • Command line activering • parameter –PprofileName • Property waarden • JDK versie • OS naam, familie, versie • (niet) Bestaan van een bestand
  • 55.
    Profiel definities • Inde pom.xml • In de profiles.xml • In de persoonlijke settings.xml • In de maven config • %MAVEN_HOME%/conf/settings.xml
  • 56.
    Settings.xml Locatie: • %MavenHome%/conf/settings.xml • %UserHome%/.m2/settings.xml •In de project folder Bevat: • Repository locaties • Proxy instellingen • Mirrors • Server access credentials
  • 57.