Maven

A preconfigured version of maven is installed on the development servers. Just type mvn. If you want to take a look at the configuration /opt/maven/conf.

Maven and Eclipse

Maven Integration for Eclipse Plug-In (m2e)

On the acc6 cluster (asl73x) m2e is preinstalled with the provided eclipse version.

On the acc7 cluster (asl74x) m2e is preinstalled with the provided eclipse version.

Configuring the Maven instance used in Eclipse

  • Path to the Maven installation:
    In the menu go to Window -> Preferences -> Maven -> Installations
    here you press the "Add..." button and choose the maven setup located at "/opt/maven". After that you can close the window by pressing "Ok".
  • global maven settings:
    In the menu go to Window -> Preferences -> Maven -> User Settings
    Global Settings should point to /opt/maven/conf/settings.xml
  • Configure the BEL archetypes repository:
    Maven: Window -> Preferences -> Maven -> Archetypes -> Add remote catalog: "GSI catalog": http://artifacts.acc.gsi.de/nexus/content/repositories/default/
  • Configure the editing of pom.xml files (optional):
    Maven: Window -> Preferences -> Maven -> User Interface -> enable "open xml page"
  • Disable index files:
    • Window -> Preferences -> Maven -> uncheck "download repository index updates on startup"
    • for each repository in the "Window -> Show View -> Other -> Maven repository" view right mouse click and check "Disable Index Details"

see also AppHowToEclipseConfiguration

Repositories

See also ArtifactRepository.

If you get a peer not authenticated Error, your java installation is missing the acc-ca Zertificate.

Authentication

To enable authentication (required to deploy artifacts, or access the SCM/Subversion) you need to manually configure your maven password settings. See http://maven.apache.org/guides/mini/guide-encryption.html for the full guide.

Please make absolutely sure you checked the file permissions on $HOME/.m2/settings-security.xml and understand the security issues resulting from it.

generate a random master password
mvn --encrypt-master-password $(openssl rand -base64 32)

store password in $HOME/.m2/settings-security.xml
<settingsSecurity>
  <master>PASSWORDHASH</master>
</settingsSecurity>

make sure permissions are good
chmod 600 $HOME/.m2/settings-security.xml

create an encrypted version of your ACC password
mvn --encrypt-password
# you will be prompted, do NOT pass it as parameter

store encrypted in $HOME/.m2/settings.xml
<?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>csco</id>
         <username>USERNAME</username>
         <password>PASSWORDHASH</password>
      </server>
      <server>
         <id>csco-snapshot</id>
         <username>USERNAME</username>
         <password>PASSWORDHASH</password>
      </server>
      <server>
         <id>www-acc.gsi.de</id>
         <username>USERNAME</username>
         <password>PASSWORDHASH</password>
      </server>
   </servers>
</settings>

Dependency Profile (csco parents or CERN artifact dependencies)

If you use the parents provided by CSCO or if you have dependencies on CERN artifacts, you need to activate an additional profile, otherwise resolving of CERN dependencies might not work properly:

To the maven ~/.m2/settings.xml file you created above in the Authentication section, add the following before the closing </settings> tag :

<profiles>
   <profile>
     <id>inject-dependencies-set-direct</id>
     <properties>
       <dependencies.set.direct>true</dependencies.set.direct>
     </properties>
   </profile>
 </profiles>

 <activeProfiles>
   <activeProfile>inject-dependencies-set-direct</activeProfile>
 </activeProfiles>

Useful Maven Commands (Cheat Sheet)

Update parent version of all child modules

Modify parent pom. Execute mvn versions:update-child-modules

Danch sollten in allen children pom's die Nummern auch erhöht worden sein.

Create a PDF or PNG of the dependencies of a project

Create a .DOT file using: mvn org.apache.maven.plugins:maven-dependency-plugin:2.3:tree -DoutputType=dot -DoutputFile=dependency.dot

To convert it to PDF: dot -Tpdf -Grankdir=LR -o dependency.pdf dependency.dot

To convert it to PNG: dot -Tpng -Grankdir=LR -o dependency.png dependency.dot

Installing 3rdParty jar in local Repository

mvn install:install-file -Dfile=foo.jar -DgroupId=org.foosoft -DartifactId=foo -Dversion=1.2.3 -Dpackaging=jar

Deploy single file

mvn deploy:deploy-file -Dfile=$FILE -DrepositoryId=csco-snapshot -DartifactId=$ARTIFACTID -DgroupId=$GROUPID -Dversion=$VERSION-SNAPSHOT -Durl=https://artifacts.acc.gsi.de/nexus/content/repositories/csco-snapshot

Checking for new dependency updates

mvn versions:display-dependency-updates

[INFO] The following dependencies in Dependencies are using the newest version:
[INFO]   com.fasterxml.jackson.core:jackson-databind .................... 2.1.3
[INFO] 
[INFO] The following dependencies in Dependencies have newer versions:
[INFO]   cmmnbuild:lsa-dbaccess ................................ 7.1.2 -> 7.2.1
[INFO]   org.hibernate:hibernate-core ................ 4.1.9.Final -> 4.2.0.CR1

Minimal pom.xml

mvn archetype:create

Create a project from a GSI-AP Java Project Template

mvn -DarchetypeGroupId=de.gsi.cs.co -DarchetypeArtifactId=csco-java-bundle-template archetype:generate

Create a simple maven java "Hello World!" project. Just a basic pom.xml, src and test folder

mvn -DarchetypeArtifactId=maven-archetype-quickstart archetype:generate

Build in parallel on several available cores

mvn -TC1 compile

Build only one module of a reactor

and all the dependencies this module requires
mvn compile -pl path/to/module -am

Multi Module Reactor build issues

In a multi module reactor project dependency resolution does not always happen as expected. mvn compile correctly resolves dependencies within the reactor. But mvn package or mvn dependency:tree resolve against repoistories (local or remote). Running mvn install to build, package and install to the local repository before packaging or checking dependency is necessary.

Fetching dependencies of a project and installing it in another local repository (linux assumed)

Add the following plugin to the plugin section of the pom.xml/project you want to fetch the dependencies for:

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-dependency-plugin</artifactId>
   <version>2.8</version>
   <executions>
      <execution>
         <id>copy-dependencies</id>
         <phase>validate</phase>
         <goals>
            <goal>copy-dependencies</goal>
         </goals>
         <configuration>
            <addParentPoms>true</addParentPoms>
            <copyPom>true</copyPom>
            <prependGroupId>true</prependGroupId>
            <!-- this will put a directory structure in target/dependency 
                 that can be used as a maven repository. Do not use this
                 together with prependGroupId -->
            <!-- useRepositoryLayout>true</useRepositoryLayout -->
         </configuration>
      </execution>
   </executions>
</plugin>

Change into the products directory and type:

mvn validate
zip dependency.zip target/dependency/*

Now copy the dependency.zip to the desired user that wants to install the artifacts in his repository (we suggest to create some kind of temporary directory for this). Login as the user, change to the (temporary) directory with the zip file and type:

unzip dependency.zip
cd target/dependency
for POM in *.pom; do JAR=$(basename ${POM} ".pom").jar; if [ -f ${JAR} ]; then mvn install:install-file -Dfile=${JAR} -DpomFile=${POM}; else mvn install:install-file -Dfile=${POM} -DpomFile=${POM}; fi; done;

Maven Quick Reference Card

http://maven.apache.org/guides/MavenQuickReferenceCard.pdf

-- ChristophHandel - 02 Feb 2012
Topic revision: r41 - 26 Oct 2020, BenjaminPeter
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki? Send feedback