.:An Endless Journey:.
open source and me
  • Immutable Page
  • Info
  • Attachments

Maven Notes

Problems

When repository are down, it will be very inconvienent.

So, a proxy repository can be very useful

Jar are not always available, expecialy those already phased out by majority.

For example: JSWDP 2.0 (JAX-RPC 1.1) I cannot found anywhere, and I need to deploy a archived copy in other local or internal repository

Declaring Dependency for Package

I've a shared / common module. The module deps on a third module, called modX, Should I declare this module 'optional'?

Is any there guideline on the use ong optional == true? If I dont' declare it as optional, dep will be pulled everthing time

Plugins

Dun known why, but I always run into situation that, some features or bugfix I've looking for, is only available in 'SNAPSHOT'.

Also, documents regarding plugins is sometimes not up-to-date (or too up-to-date ie, only valid for SNAPSHOT version). As a result, reading the document is not always helps, but sometimes can confusing you.

Buggy for properties/profile/multi-module

Actually, more issue on these

Tips

Extra JVM options for Maven

  export MAVEN_OPTS="-Xmx256m"

Maven and JPA (Hibernate)

How to use snapshot plugins

From: http://maven.apache.org/guides/development/guide-plugin-snapshot-repositories.html

The pluginRepositories block can be plainly included in pom.xml instead of settings.xml Within <plugins> block, you may need to explicitly define the version of plugin to use

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <version>2.0-alpha-1-SNAPSHOT</version>
    <executions>
      <execution>
        <id>copy-dependencies</id>
        <phase>package</phase>
        <goals>
          <goal>copy-dependencies</goal>
        </goals>
        <configuration>
          <outputDirectory>${project.build.directory}</outputDirectory>
          <overWriteReleases>false</overWriteReleases>
          <overWriteSnapshots>true</overWriteSnapshots>
        </configuration>
      </execution>
    </executions>
  </plugin>

Quick Ref.

Less freq. use but useful commands

  mvn install -DcreateChecksum=true (-DcreatePom=true or -DpomFile={pomfile})
  mvn source:jar javadoc:jar
  mvn install:install-file -DgroupId={groupId} -DartifactId={artifactId}
                           -Dversion={version} -Dpackaging=jar -Dfile={artifact.jar} 
                           -Dclassifier=sources -DcreateChecksum=true
  mvn install:install-file -DgroupId={groupId} -DartifactId={artifactId} 
                           -Dversion={version} -Dpackaging=jar -Dfile={javadoc.jar} 
                           -Dclassifier=javadoc -DcreateChecksum=true

  mvn install:install-file -Dfile=javaee.jar -DgroupId=javax -DartifactId=javaee-api
                           -Dversion=5 -Dpackaging=jar

  mvn archetype:create -DgroupId=com.cascade_limited.mss -DartifactId=core-model

  mvn javadoc:javadoc
  (firefox target/site/apidocs/index.html)

Deploying to internal repos

  <!-- In pom.xml -->
  <distributionManagement>
    <repository>
      <id>internal.repos.release</id>
      <name>Internal Maven2 Release Repository</name>
      <url>file:///var/www/html/maven/internal/release</url>
    </repository>
    <snapshotRepository>
      <id>internal.repos.snapshot</id>
      <name>Internal Maven2 Snapshot Repository</name>
      <url>file:///var/www/html/maven/internal/snapshot</url>
    </snapshotRepository>
  </distributionManagement>

Then, "mvn deploy"

  In settings.xml
  <profiles>

    <profile>
      <id>defaultProfile</id>
      <repositories>
        <!--
        || Internal release repository (Released module and non-distributed material)
        -->
        <repository>
          <id>internal-repos-release</id>
          <name>Internal Repository For Release Artifacts</name>
          <url>http://219.76.67.58/maven/internal/release</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
        </repository>
        <!--
        || Internal snapshot repository
        -->
        <repository>
          <id>internal-repos-snapshot</id>
          <name>Internal Repository For Snapshot Artifacts</name>
          <url>http://219.76.67.58/maven/internal/snapshot</url>
          <releases>
            <enabled>false</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
          </snapshots>
        </repository>
      </repositories>
    </profile>

  </profiles>

  <activeProfiles>
    <activeProfile>defaultProfile</activeProfile>
  </activeProfiles>

inject a file into internal repository

  mvn deploy:deploy-file
      -Durl=file:///var/www/html/maven/internal/release
      -Drepository.id=internal-repos-release
      -Dfile=lib/ireasoningsnmp.jar
      -DgroupId=com.ireasoning
      -DartifactId=snmpv3
      -Dpackaging=jar
      -Dversion=4.0
      -DgeneratePom=true
      -DgeneratePom.description="Injected 3rd party java. Eval version, download by 2007-01-08"

  # If you have a working 'pom'
  # It is needed if the artifact have dependency on other libraries
  mvn deploy:deploy-file
      -Durl=file:///var/www/html/maven/internal/release
      -Drepository.id=internal-repos-release
      -Dfile=a4j-trinidad-1.1.1.jar
      -DgroupId=org.ajax4jsf
      -DartifactId=a4j-trinidad
      -Dpackaging=jar
      -Dversion=1.1.1
      -DpomFile=a4j-trinidad-1.1.1.pom