MAVEN - mosinn/DOCS-n-Snippets-n-Steps GitHub Wiki
- Installation is just zip download
- Then Make sure env var JAVA_HOME is set
- Then set env var MAVEN_HOME or M2_HOME as uzip root
- Then append path and move up, as %M2_HOME%\bin
- Make sure highest/first path is %JAVA_HOME%\bin
- %M2_HOME%\conf\settings.xml , is where we can specify repo URLs to use to look for artifacts
- Sometimes MVN install fails with SSL path issue, so use browser Artifactory URL to download ALL certs
- Then use keytool to import into cacerts
- OR, ask someone to directly provide the cacerts file and replace the %JAVA_HOME%\jre\lib\security\cacerts
- mvn install -U
- POM.build tag is where we can either override default behaviors of maven commands say goals say plugins
- mvn install -X
- use >> to fix errors:
- mvn install -X >> C:\U\mvndebug.txt
- clean is NOT COUPLED with any other goal, so is called explicitly when needed. Rest of goals seem daisy chained
- compile just creates classes in target dir
- package runs compile first then runs JUNIT (not integration), then creates packaged eg .jar out of then and just puts it in target\classes dir
- install > runs clean then compile then package, then puts the package in local repo > USER_HOME.m2
- deploy does install then also pushes the artifact in REMOTE ARTIFACTORY REPO. It doesn't really deploy in a server
- DEFAULT location is user_home\<hidden .m2>
- check or update %M2_HOME%\conf\settings.xml
* <localRepository>C:\U\\.m2\repository</localRepository>
The JARs must be placed in the local repository in the correct place in order for it to be correctly picked up by Apache Maven:-
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> \ -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
mvn install:install-file -Dfile=<path-to-file> -DpomFile=<path-to-pomfile>
mvn install:install-file -Dfile=<path-to-file>
Discover repo name to add in M2Home>conf>settings.xml, if say build fails and it gives us artifact name ?
- Search failed artifact name in artifactory using browser , but replace : with -
- Eg, error in MVN saying failed ~ maven-nls-plugin:2.1.0-SNAPSHOT, can be searched in browser as maven-nls-plugin-2.1.0-SNAPSHOT
- Then when we find the artifact using online artifactory browser, its results shows like ARTIFACT | PATH | REPOSITORY |
- REPO URL to put in setting.xml is
<BROWSER-URL>\| REPOSITORY |
- VERIFY minimal path edited as
<host-name>\artifactory\ |REPOSITORY|
gives chrome browser result - UPDATE M2_HOME>conf>settings.xml with newly discovered path OR if it fails, try download jar and local install
- IDE>Settings>Maven gives option to point to settings.xml & repo for standalone Maven, so that IDE issues get resolved as well
- Online Artifactory access
- Online Artifactory URL
- ALL REPO NAMES involved, so we can add them in settings
- CERTS or cacerts file, so we can use keytool or overwrite
-
<project>
contains 5 Elements: "GAV MP B-nested"<groupId><artifactId><version 1.0-SNAPSHOT convention><modelVersion 4.0.0 mostly></packaging> <build></build>
- Last "build" is nested element used to specify JAVA compiler as plugins:
- it is a list of plugin entries where each then again is having "GAV Config-nested"
- Eg:
<project>
<groupId>com.myorg</groupId>
<artifactId>my-app-name</artifactId>
<version>1.0.0-SNAPSHOT</version>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>8</release>
</configuration>
</plugin>
</plugins>
</build>
</project>
<dependencies><dependency> GAV </></> is used
- MAVEN_HOME\conf\settings TELLS the REPO URL, then below tells deep link path:-
- G tells website repo hostname /CHANGED POSTfix path in same format to give uniqueness but dots replaced by / in browser
- A tells AS-IS /url-path further, of a specific application/tool
- V tells AS-IS which version as / to specify further deep link
- P is used to append A+V+AS-IS-P to /V eg .jar, to provide deep link download url
- ie AVP is actual artifact NAME
- eg for above maven complier plugin deep link url which maven will generate is :
- https://repo1.maven.org/maven2/org/apache/maven/plugins/maven-compiler-plugin/3.8.1/maven-compiler-plugin-3.8.1.jar
- It is special convention in version tag, and lets use LATEST code for version perfix eg 1.0.0-SNAPSHOT could download 1.0.0.99 when mvn compile is run
- To provide sure shotness, NEVER go to PROD with -SNAPSHOT in pom. Go with say -FINAL or -RELEASE
- ProjectRoot\src\main\java\ > com.myorg.Hello.java
- -Dmaven.test.skip=true
- -Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true