Intro to Maven - raisercostin/software-wiki GitHub Wiki
- Maven Project Layout
- Introduction to the Standard Directory Layout
- structure
pom.xml <-- project definition .gitignore <-- not maven specific but present in git projects README.md <-- not maven but useful for github: a markdown file src/ <-- sources main/ <-- sources needed for library java/ <-- java sources resources/ <-- other files that will be added to library and reachable in classpath webapp/ <-- java web application resources scripts/ php/ <-- other type of resources. With different compilators. scala/ test/ <-- sources for Unit Tests. will not be bundled in library java/ <-- sources resources/ <-- sources it/ <-- sources for Integration Tests. will not be bundled in library java/ resources/ target/ <-- generated files. Can be deleted to remove all generated files.
- Convention Over Configuration
- artifacts (libraries, sources, docs, pom, metadata) - sample
- library unique id:
<groupId>:<artifactId>:<version>
- groupId - is the group that manages the artifact/library. Is the reversed domain name to ensure the uniqueness of the group based on the domain uniqueness.
- artifactId - is the artifact unique id inside a group. The artifact is the generalized name for a library. Could also be an archive with sources, documents, metadata etc.
- version - is the version of the artifact. For details see semantic versioning.
- library dependencies
- repositories
- Transitive Dependencies
- library unique id:
- declarative build tool
- actions
-
phases and lifecycle
These are executed via
mvn <phase>
:mvn clean
,mvn compile
,mvn test
-
plugins
These are executed via
mvn <plugin>:<plucinCommand>
:mvn eclipse:clean
,mvn eclipse:eclipse -DdownloadSources
,mvn origin:origin -DdownloadSources
- formatting :
mvn formatter:format
,mvn antrun:run
-
phases and lifecycle
These are executed via
- Better Builds With Maven - free maven book - http://www.scribd.com/doc/238927/Better-Builds-With-Maven
- https://maven.apache.org/articles.html
- https://maven.apache.org/guides/getting-started/maven-in-five-minutes.html
- https://maven.apache.org/guides/getting-started/index.html
- manage integration with IDE: where are sources, dependencies, ...
- automatic download of libraries, sources
- no scm (git) pollution with binary files
- manage transitive dependencies
- manage integration with build servers: Jenkins needed for Continuous Integration
- Where to find libraries?
- Use mvnrepository to find libraries and versions - https://mvnrepository.com/artifact/junit/junit/4.12
- See lib.jar, lib-sources.jar and lib.pom http://central.maven.org/maven2/junit/junit/4.12/
- Search libraries by classes inside them: http://grepcode.com/file/repo1.maven.org/maven2/com.google.guava/guava/r09/com/google/common/base/Preconditions.java
- https://javalibs.com/artifact/org.springframework.plugin/spring-plugin-core
- No compiler on
mvn compile
- Check if maven can access your java compiler:
javac -version
- See Config Java Tools
- Check if maven can access your java compiler:
- Download from
Unzip
Configuration files are in
<maven-install-folder>/config/settings.xml
~/.m2/settings.xml
To configure credentials for servers (revomatico-repo, revomatico-repo-snapshots, revomatico-repo-site for example) you can add them to any of the settings.xml
. See how to store them encrypted
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>revomatico-repo</id>
<username>raisercostin</username>
<password>********</password>
</server>
<server>
<id>revomatico-repo-snapshots</id>
<username>raisercostin</username>
<password>********</password>
</server>
<server>
<id>revomatico-repo-site</id>
<username>raisercostin</username>
<password>********</password>
</server>
</servers>
</settings>
- don't forget to add
..\apache-maven\bin
to your PATH environment variable.
sudo apt-get update
sudo apt-get install maven
> echo $M2_HOME
> echo %M2_HOME%
> echo $PATH|grep maven
> echo %PATH%|grep maven
> mvn -version
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T18:41:47+02:00)
Maven home: C:\dev\apache-maven\bin\..
Java version: 1.8.0_121, vendor: Oracle Corporation
Java home: D:\forgerock\jdk1.8.0_121\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "dos"
mvn archetype:generate
> template: maven-archetype-quickstart
> version: 1.1
> groupId: ro.dcsi.internship
> artifactId: usersync
> version: 1.0-SNAPSHOT
> package: ro.dcsi.internship
- Windows
cd \dev\apache-maven
cd mvn-workspace
dir ..\
mvn archetype:generate
dir
mvn help:effective-pom
cd ship1
mvn help:effective-pom
mvn test
mvn clean
mvn test
mvn eclipse
mvn eclipse:help
mvn eclipse:eclipse
mvn run
mvn exec:java -Dexec.mainClass=ro.dcsi.internship.App
# display last plugin versions
mvn versions:display-plugin-updates
12606 java -version
12607 javac -version
12608 mvn -version
12609 mvn archetype:generate
12610 mc
12611 pwd
12612 cd work
12613 mvn archetype:generate
12614 mvn archetype:generate
12615 history