====== [[http://maven.apache.org/|Maven]] ====== ===== Basic setup of Maven ===== - Download and install Maven+JDK as described [[http://maven.apache.org/download.html#Installation|here]]. - Tune system variables. You need to create ''JAVA_HOME'' and ''M2_HOME'' variables and append the path to maven's bin directory to your path, as shown on below screenshot: {{ maven_environment.gif?300|}} - Maven needs the initial configuration to setup HTTP proxy (if you have it in your office). The following configuration file((See [[http://maven.apache.org/ref/2.0.8/maven-settings/settings.html|here]] the complete list of options for ''settings.xml'')) should be placed to ''C:\Documents and Settings\\.m2'' directory: mylocalproxy true http proxy 8080 Maven does not support the configuration of both HTTP and HTTPS proxy (see [[codehaustracker>MNG-2305]]). - You need to deploy all libraries, which are missed in public Maven repositories: call mvn install:install-file -Dversion=0.1-SNAPSHOT -Dpackaging=jar -DgroupId=org.company.package -DartifactId=library-name -Dfile=library.jar - Checkout the projects needed, better using Eclipse .psf file. - Run the following commands: * To build the complete project and create a packaged ZIP file with editor: \\ ''mvn install package'' \\ As the result the following package is build, which is a packaged application: ''project_folder\target\project.zip'' * To generate Eclipse classpaths from POMs run: \\ ''mvn eclipse:eclipse'' * For the quick install (no tests and no updates from remote repositories) run: \\ ''mvn -Dmaven.test.skip=true -o install'' Unfortunately, it is hardly possible to make an assembly in ''nn_build'' project (see [[http://mail-archives.apache.org/mod_mbox/maven-users/200709.mbox/%3C9AB4FF82-4097-4391-B1DC-9C7A7217D9E0@commonjava.org%3E|1]], [[http://www.nabble.com/Problem-attaching-assembly-to-multi-module-pom-project-td13063505.html#a13063505|2]], [[http://www.sonatype.com/books/maven-book/reference/assemblies-set-dist-assemblies.html|3]]). So the assembly is done in a project, which contains the main class. This allows also the assembly to be bound to "package" goal. ===== Developing C++ projects with maven ===== * [[http://docs.codehaus.org/display/MAVENUSER/Projects+With+JNI|Projects With JNI]] * [[codehausmojo>maven-native/native-maven-plugin/|native-maven-plugin]] * [[http://java.freehep.org/freehep-nar-plugin/intro.html|freehep-nar-plugin]] * [[codehausmojo>rpm-maven-plugin|rpm-maven-plugin]] ===== Questions answered ===== === Where can I get more information about maven? === Read [[http://www.sonatype.com/books/maven-book/reference/public-book.html|Maven Book: The Definitive Guide]]. === Where I can get more detailed explanation about POM? === See [[http://maven.apache.org/pom.html|here]]. === What is the build phases sequence (lifecycle)? === See [[http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Lifecycle_Reference|here]]. === What is project's version number? === See [[http://www.sonatype.com/books/mvnref-book/reference/pom-relationships-sect-pom-syntax.html#pom-reationships-sect-versions|Project Versions]] and [[github>SpringSource/spring-build-gradle/wiki/Spring-project-versioning|Spring project versioning]]. === What is maven "super POM"? === All POMs extend the Super POM unless explicitly set. It defines the central repository location, defines the "release-profile", and since maven v2.0.9 also freezes the versions for core plugins. See [[http://maven.apache.org/guides/introduction/introduction-to-the-pom.html#Super_POM|here]] the complete definition, which you may also extract from maven distribution (e.g. ''lib\maven-x.x.x-uber.jar/org\apache\maven\project\pom-4.0.0.xml''). === How to print the "effective POM"? === [[http://www.sonatype.com/books/mvnref-book/reference/pom-relationships-sect-effective-pom.html|Effective POM]] is a combination (merge) of all parent POMs with a current. You can learn it from the output of ''mvn help:effective-pom''. === What is the sequence about how effective POM is formed? === From [[http://maven.apache.org/ref/3.1.1/maven-model-builder/|Maven Model Builder]]: * profile activation * profile injection * parent resolution until super-pom * model variables (''${...}'') interpolation === What are Maven alternatives? === General: * [[stackoverflow>902693|Is there a successor to Ant and Maven?]] * [[stackoverflow>385401|Maven replacement?]] * [[stackoverflow>303853|What are your impressions of Maven?]] [[http://buildr.apache.org/|Buildr]] / [[http://gradle.org/|Gradle]]: * [[stackoverflow>1015525|Why use Buildr instead of Ant or Maven?]] * [[stackoverflow>1163173|Why use Gradle instead of Ant or Maven?]] * [[stackoverflow>7056186|Buildr vs Gradle]] * [[stackoverflow>5382410|Gradle vs Gant]] * [[habrahabr>275515|Gradle: управляя зависимостями]] Maven vs Ant: * [[stackoverflow>603189|Differences between Ant and Maven]] * [[stackoverflow>80622|Maven or Ant]] * [[stackoverflow>318804|Maven or Ivy for Managing Dependencies from Ant?]] * [[http://ptrthomas.wordpress.com/2009/03/08/why-you-should-use-the-maven-ant-tasks-instead-of-maven-or-ivy/|Why you should use the Maven Ant Tasks instead of Maven or Ivy]] === How to print the help for plugin configuration options? === Use ''mvn help:describe -DgroupId=org.apache.maven.plugins -DartifactId=maven-dependency-plugin -Dfull=true''. === How to integrate Maven into Java application? === From [[stackoverflow>1487802|Calling Maven goals from Java]] and [[stackoverflow>5296271|Can I use Maven repository manager outside of Maven?]]: * Use [[http://maven.apache.org/embedder.html|Maven Embedder API]] if you want to call something like ''mvn clean package'' * Use [[https://docs.sonatype.org/display/AETHER/Home|Aether]] if you want to benefit from Maven dependency resolution mechanizm. === How to use Ant plugins with ''maven-antrun-plugin''? === The given example shows how to export functions from ''ant-contrib'' library (on example of ''[[http://ant-contrib.sourceforge.net/tasks/tasks/propertyregex.html|]]''): maven-antrun-plugin 1.8 ant-contrib ant-contrib 1.0b3 ant ant process-resources run ==== Running Maven ==== === How to define Java heap space for maven? === Use ''MAVEN_OPTS=-Xmx512m''. To increase the memory for test cycle in case when Unit test execution is run in a forked JVM, use ''-Xmx756m'' option for ''maven-surefire-plugin''. === How to hide the progress information (KB downloaded/uploaded) from Maven output e.g. for ''maven-deploy-plugin''? === Use ''-B'' (batch) Maven option key. === How to separate unit and integration tests? === [[stackoverflowa>3209506/267197|The idea]] is to bind ''maven-surefire-plugin'' to two phases (''test'' and ''integration-test'') with different configuration settings. Also check [[stackoverflow>19826068|Combining profiles in Maven to skip multiple categories of unit tests]] concerning how to fine-tune which tests to run. === Why my Unit tests are run twice? === You have Cobertura plugin enabled. From [[stackoverflowa>868348/267197|Running junits and cobertura with maven]]: Cobertura runs Unit tests both for original and instrumented code to make sure that instrumentation has not introduced bugs. === How to disable unit test for a particular project? === There is no handy options for that (similar to ''-Dmaven.test.skip=true'') so one need to define the following profile: disable-unit-tests maven.test.skip.myproject true maven-surefire-plugin true and then say ''mvn -Dmaven.test.skip.myproject=true install'' Unfortunately it is not possible to generalize this profile and put to parent POM, see [[stackoverflow>21477306|Disable unit tests in a submodule using system property]]. === How to configure Maven to use custom ''settings-security.xml''? === From [[codehaustracker>MNG-4853]]: Use ''-Dsettings.security=path/to/security-settings.xml''. === How to exclude given repository from being mirrored? === From [[http://maven.apache.org/guides/mini/guide-mirror-settings.html#Advanced_Mirror_Specification|Advanced Mirror Specification]]: For example, to bypass repository ''vaadin-addons'' use the following configuration: http://repository.internal/nexus/content/groups/development *,!vaadin-addons extra-repositories vaadin-addons http://maven.vaadin.com/vaadin-addons extra-repositories === How to configure Maven to check for ''-SNAPSHOT'' versions less frequent? === Indeed for big projects checking for ''-SNAPSHOT'' versions each time the dependency is resolved slows down the project build. The way out is to override the default ''daily'' in your ''settings.xml'' and set it for 10 days (14400 minutes): central http://central true daily true interval:14400 === How to speedup maven build? === From [[habrahabr>141393|Ускоряем процесс сборки с maven]]: * Use ''-T'' option to run build in parallel threads: \\ * ''%%alias mvnn='mvn -T4'%%'' -- always use 4 threads * ''%%alias mvnn='mvn -T1.0C'%%'' -- use number of CPUs multiplied by ''1.0'' (with two CPU cores the number of threads will be ''2''). * Use ''mvnsh'' -- a background process to keep maven always loaded into memory * Use ''-o'' switch not to update dependencies / or check [[#how_to_configure_maven_to_check_for_-snapshot_versions_less_frequent|How to configure Maven to check for ''-SNAPSHOT'' versions less frequent?]] From [[habrahabr>266011|Takari: Maven на стероидах]]: * Download ''[[https://repo1.maven.org/maven2/io/takari/aether/takari-local-repository/0.11.2/takari-local-repository-0.11.2.jar|takari-local-repository-0.11.2.jar]]'' and ''[[https://repo1.maven.org/maven2/io/takari/maven/takari-smart-builder/0.6.1/takari-smart-builder-0.6.1.jar|takari-smart-builder-0.6.1.jar]]'' (check for later version) and put them to ''maven/lib/ext/''. In combination with above one can enable smart build using the following alias: \\ ''%%alias mvnn='mvn -T1.0C --builder smart'%%'' * Extra optional setting: ''%%export MAVEN_OPTS="-Xmx1200m -XX:+TieredCompilation -XX:TieredStopAtLevel=1"%%'' === How to print system properties? === maven-antrun-plugin initialize run === How to pass system properties to ''maven test'' task? === * The latest v2.6 of the plugin allows to pass the options via command-line as ''-Dname=value'' (fixes [[codehaustracker>SUREFIRE-121]]). * From v2.5 you can use '''' configuration option of surefire plugin (see [[http://www.cowtowncoder.com/blog/archives/2010/04/entry_385.html|here]]): maven-surefire-plugin proxy 8080 * In v2.4.3 of the plugin the '''' behaviour is broken. Also the parent JVM variables are not copied to forked JVM (see [[codehaustracker>SUREFIRE-491]]). The only working configuration is: maven-surefire-plugin -ea -Xmx756m -Dhttp.proxyHost=proxy -Dhttp.proxyPort=8080 === How to configure several source directories for maven project? === This can be achieved using ''build-helper-maven-plugin'' like below: 4.0.0 org.mycompany project jar 1.1 org.codehaus.mojo build-helper-maven-plugin add-source generate-sources add-source ${basedir}/import === [[stackoverflow>5820375|How to strip one folder from path during resource copy]]? === This can be achieved by using ''[[https://ant.apache.org/manual/Types/mapper.html#cutdirs-mapper|]]'' (see also ''[[https://ant.apache.org/manual/Types/mapper.html#flatten-mapper|]]'' which removes all folders). org.apache.maven.plugins maven-antrun-plugin run === [[stackoverflow>3365553|How to generate site using maven, ignoring test results?]] === Use ''mvn -Dmaven.test.error.ignore=true install site'' === [[stackoverflow>2871054|How to set plugin's version on the command line?]] === Example: ''mvn org.apache.maven.plugins:maven-dependency-plugin:2.9:tree > tree'' === [[github>mojohaus/exec-maven-plugin/issues/78|Cannot use custom protocol handler when executing the program]] === Both ''maven-surefire-plugin'' and ''exec-maven-plugin'' are impacted by this issue. ''[[javase>docs/api/java/net/URL.html|java.net.URL]]'' cannot resolve protocol handler for isolated classloader which is set up by Maven. Workaround is to use custom ''URLStreamHandlerFactory'' which can locate the handler class (e.g. provided by runtime dependency): static class HttpHandlerFactory implements URLStreamHandlerFactory { private final URLStreamHandler handler; public HttpHandlerFactory(URLStreamHandler handler) { this.handler = handler; } @Override public URLStreamHandler createURLStreamHandler(String protocol) { if (protocol.equals("http")) { return handler; } return null; } } public static void main(String[] args) throws Exception { try { Class cl = Class.forName("org.mycompany.protocol.http.Handler"); URL.setURLStreamHandlerFactory(new HttpHandlerFactory((URLStreamHandler) cl.newInstance())); } catch (ClassNotFoundException e) { // Specific handler is not in the classpath } ... } See also: * [[https://gcc.gnu.org/bugzilla/show_bug.cgi?id=22754|java.net.URL#getURLStreamHandler() uses wrong classloader]] -- suggests to use ''Thread.currentThread().getContextClassLoader()''. * [[https://issues.apache.org/jira/browse/SUREFIRE-104#comment-14453483|Unable to establish my own http protocol handler for unit tests]] ==== Profiles ==== === Are maven profiles inherited? How to "import" profiles? === No, maven profiles are not inherited and not merged as dependencies for example. When activated, the profile is applied directly to the parent POM prior to being used for merging with the child. This leads to certain limitations, e.g. you cannot define the profile partially in parent POM and extend it in a child. Also if you need the profile ''my'' in module ''A'' to have impact on dependent module ''B'' you need to activate a profile during a multi-module build, but build only one module (''mvn -Pmy -pl B'', see [[stackoverflow>3532297|here]]). However it is possible to activate profiles in dependent artifact, e.g. as described in [[codehaustracker>MNG-1388]]. === [[stackoverflowa>40938111/267197|How to negate a property in pom.xml?]] === The profile basically negates the value of "failOnError" property: true failOnError failOnError false org.apache.maven.plugins maven-surefire-plugin true === How to override plugin configuration in profile? === Suppose that one has parent POM that defines the following profile: doit maven-antrun-plugin step1 install run And now one wants to extend this profile in module POM in a way that more steps are executed in addition to above. One need to create profile with same profile ID, but choose different execution ID: doit maven-antrun-plugin step2 install run Now if ''mvn -Pdoit'' is executed, you will see ''Step1 Step2'' printed to console. For more advanced merging facilities check [[http://www.sonatype.com/people/2011/01/maven-how-to-merging-plugin-configuration-in-complex-projects/|Maven How-To: Merging Plugin Configuration in Complex Projects]] (''%%combine.children="append"%%'' to append children, ''%%combine.self="override"%%'' to ignore children for the parent being overridden). Note that you can't merge e.g. ''build.resources'' the same way: use ''build-helper-maven-plugin'' to achieve that: org.codehaus.mojo build-helper-maven-plugin initialize add-resource src/main/extra ==== Dependency management ==== === What is the consequence of leaving out Maven plugin version? === From [[stackoverflow>8711914]]: When version is omitted, maven tries to find and uses the most recent version. The real problem here is that you never know which version of the plugin was used and will the plugin behave the same in the future. This makes builds unreproducible/unrepeatable. === How to exclude dependencies from dependent tree? === To view the dependency tree use ''mvn dependency:tree''. And see [[http://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html|here]]. === How to import dependency management rules from other POM? === As multiple inheritance is not supported by Maven POM hierarchy, it is still possible to inherit dependency management rules from other POMs. You should include the reference to the interested POM into ''dependencyManagement'' with ''import'' scope (example was taken from [[http://docs.codehaus.org/display/MAVEN/Importing+Managed+Dependencies|here]]): org.test common-libs 1.0 pom import Note that version ranges are not supported if dependencies are inherited either from parent POM or the way above (see [[codehaustracker>MNG-2199]]). === Is it possible to define the "group" dependency? === There is no way to do it directly as mentioned in [[codehaustracker>MNG-2059]]. But you can define them in POM artifact and put a dependency on it. === How to display the dependency tree for **plugins**? === As from [[stackoverflow>7074590|here]] just follow ''mvn -X'' output. ==== Artifact management ==== === How enable the deployment of JAR artifact for WAR project? === How can I make maven to create and install two artifacts with different packaging? For example, how to deploy JAR artifact next to WAR artifact when POM packaging is ''war''? If you have a ''war'' packaging in your ''pom.xml'' and you want to create a JAR file together with WAR file, try this command: ''mvn -o jar:jar install:install-file -Dfile=${project.build.directory}\${project.artifactId}-${project.version}.jar -Dpackaging=jar -DpomFile=pom.xml'' In latest WAR plugin versions it is possible to specify the [[http://maven.apache.org/plugins/maven-war-plugin/war-mojo.html#attachClasses|attachClasses option]] to achieve the same effect: ''true''. Also using profiles like in [[http://maven.apache.org/guides/mini/guide-building-for-different-environments.html|Building For Different Environments with Maven 2]] may help. === [[stackoverflow>17997731|What is the location of resources in ''META-INF'' for WAR?]] === Depending on how this resource is going to be used, its location may vary: * If it will be read by web application container (like Tomcat ''META-INF/context.xml''), then it should be placed to ''src/webapp/META-INF/context.xml''. * If it will be used by web application itself (like AspectJ ''META-INF/aop.xml'', or Hibernate ''META-INF/hibernate.xml'', or any other via ''[[javase>docs/api/java/lang/Class.html#getResource(java.lang.String)|String#getResource()]]''), then it should be placed to ''src/main/resources/META-INF/aop.xml''. === How to share resources between maven projects? How to put JAR artifact to WAR as a resource (e.g. applet code)? === See [[http://wiki.community.objectware.no/display/smidigtonull/Maven+Dependencies+and+Build+Stability+FAQ#MavenDependenciesandBuildStabilityFAQ-mavenassemblypluginandmavendependencyplugin|here]] and [[http://www.sonatype.com/people/2008/04/how-to-share-resources-across-projects-in-maven/|here]]. The example below shows how to copy resources from ''supplier-project'' to ''consumer-project/target/addon'' folder: 4.0.0 org.mycompany consumer-project jar 1.1 org.mycompany.common supplier-project 1.0 provided org.apache.maven.plugins maven-dependency-plugin generate-sources unpack-dependencies ${project.build.directory}/addon org.mycompany.common supplier-project For the WAR file (e.g. when [[stackoverflow>7120937|adding an applet]]) use the same technique: org.apache.maven.plugins maven-dependency-plugin prepare-package copy ${project.groupId} applet-artifact-id ${project.build.directory}/${project.build.finalName}/applet true === How to share test code between projects? === For the ''test-common'' project add to your pom the following: maven-jar-plugin test-jar and then use the resulting jar artifact with ''tests'' classifier in ''test'' scope: ${project.groupId} text-common 0.1 tests test === How to create a ZIP archive with script to run the program? === In contrast to all-in-one executable JAR which can be created using ''[[https://maven.apache.org/plugins/maven-shade-plugin/examples/executable-jar.html|maven-shade-plugin]]'' or ''[[https://maven.apache.org/shared/maven-archiver/examples/classpath.html#Make|maven-jar-plugin]]''((This solution still needs dependencies to be bundled or copied somehow)), we need to create ZIP file which after unpacking will result ''run.cmd'' and all dependencies in ''lib'' folder. This gives more control over the JVM settings (e.g. heap size). ... package.Main lib commons-logging commons-logging log4j log4j runtime maven-dependency-plugin build-classpath package build-classpath ${classpath.prefix} classpath.all maven-assembly-plugin assemble-zip-package package single src/main/package/assembly.xml false maven-jar-plugin default-jar dummy package zip ${classpath.prefix} ${build.outputDirectory} ${classpath.prefix} src/main/package/run.cmd / true Note that adding the ''lib'' folder to classpath is necessary as that folder will contain e.g. main class as well as resources: java -cp "${classpath.prefix}${path.separator}${classpath.all}" ${main.class} %1 === How can I optimize all-in-one JAR? === I have assembled all-in-one jar, however there are classes which are never used by the application. How they could be automatically removed from the package to make it smaller? From [[stackoverflow>3817666|Minimizing jar dependency sizes]]: Try ''[[http://maven.apache.org/plugins/maven-shade-plugin/|maven-shade-plugin]]'': * Use the following Maven configuration: all maven-shade-plugin 2.0 package shade true true ${jar.final.classifier} commons-logging:commons-logging ** * See [[stackoverflowa>9762835/267197|Including specific classes to uber-jar]] * [[codehaustracker>MSHADE-97|Add the ability to specify "entry points" for minimizeJar]] would be nice to have. Try [[googlecode>p/genjar2/|GenJar]] (generally, didn't worked well for me): * Download [[googlecode>p/genjar2/source/checkout|sources]]. Compile with Ant. * Remove ''org.apache.tools'' package from resulting ''build/lib/genjar.jar'' (otherwise there will be problems as ''maven-antrun-plugin'' is compiled against future versions of Ant). * Install to your local repository: \\ ''mvn install:install-file -Dfile=genjar.jar -DgroupId=net.sf.genjar -DartifactId=genjar -Dversion=1.0 -Dpackaging=jar'' * Use the following Maven configuration: org.mycompany.myproject.Main all ${project.build.directory}/${project.artifactId}-${project.version}-${jar.final.classifier}.jar maven-antrun-plugin minify-jar package run net.sf.genjar genjar 1.0 * The problem was that runtime classes cannot be specified for inclusion (see [[googlecode>p/genjar2/issues/detail?id=1|issue#1]]). Try [[http://proguard.sourceforge.net/#manual/ant.html|ProGuard]]: * Use the following Maven configuration: org.mycompany.myproject.Main jar-with-dependencies all maven-assembly-plugin package-jar-with-dependencies package single ${jar.assembly.classifier} true false true com.github.wvengen proguard-maven-plugin 2.0.6 minify-jar package proguard true ${jar.final.classifier} true false false ${project.artifactId}-${project.version}-${jar.assembly.classifier}.jar ${java.home}/lib/rt.jar ${java.home}/lib/jsse.jar net.sf.proguard proguard-base 4.8 runtime * The problem ''[[https://sourceforge.net/p/proguard/bugs/376/|java.lang.ClassFormatError: LVTT entry for ... does not match any LVT entry]]'' is solved by adding ''-optimizations !code/allocation/variable'' (from [[stackoverflowa>13877518/267197|here]]). * The problem ''ClassFormatError: Invalid index N in LocalVariableTable in class file ...'' is solved by using ''-dontoptimize'' (see [[http://proguard.sourceforge.net/manual/troubleshooting.html#classformaterror2|Troubleshooting]]). Finally, check other [[http://proguard.sourceforge.net/#alternatives.html|alternatives]]. === How to add SCM build number and build date to ''jar'' MANIFEST? === From [[http://rterp.wordpress.com/2012/03/16/stamping-version-number-and-build-time-in-properties-file-with-maven/|Stamping Version Number and Build Time in a Properties File with Maven]]: One need to enable filtering and use additional bridging variable, for example ''${timestamp}'': ${maven.build.timestamp} yyyy-MM-dd src/main/resources true Another alternative is to use ''[[http://mojo.codehaus.org/buildnumber-maven-plugin/plugin-info.html|buildnumber-maven-plugin]]''. To achieve this one need to activate ''buildnumber-maven-plugin'' twice (one per each goal): maven-jar-plugin true ${project.scm.developerConnection} ${project.buildNumber} ${project.buildDate} maven-war-plugin true ${project.scm.developerConnection} ${project.buildNumber} ${project.buildDate} org.codehaus.mojo buildnumber-maven-plugin create-buildnumber validate create project.buildNumber create-timestamp validate create-timestamp yyyy-MM-dd project.buildDate === Artifacts cannot be fetched from ''repo1'' with wget. Why? === This request fails: $ wget -S http://repo1.maven.org/maven2/org/apache/commons/commons-compress/1.0/commons-compress-1.0.jar.md5 --22:44:21-- http://repo1.maven.org/maven2/org/apache/commons/commons-compress/1.0/commons-compress-1.0.jar.md5 => `commons-compress-1.0.jar.md5' Resolving repo1.maven.org... 38.97.124.18 Connecting to repo1.maven.org|38.97.124.18|:80... connected. HTTP request sent, awaiting response... HTTP/1.1 403 Forbidden Server: nginx/0.7.62 Date: Mon, 08 Mar 2010 21:44:26 GMT Content-Type: text/html Content-Length: 169 Connection: keep-alive 22:44:21 ERROR 403: Forbidden. but this succeeds: 22:44 ws1.grid.sara.nl:/home/dmitry dmitry$ man wget 22:44 ws1.grid.sara.nl:/home/dmitry dmitry$ wget -S --user-agent="Mozilla" http://repo1.maven.org/maven2/org/apache/commons/commons-compress/1.0/commons-compress-1.0.jar.md5 --22:44:52-- http://repo1.maven.org/maven2/org/apache/commons/commons-compress/1.0/commons-compress-1.0.jar.md5 => `commons-compress-1.0.jar.md5' Resolving repo1.maven.org... 38.97.124.18 Connecting to repo1.maven.org|38.97.124.18|:80... connected. HTTP request sent, awaiting response... HTTP/1.1 200 OK Server: nginx/0.7.62 Date: Mon, 08 Mar 2010 21:44:57 GMT Content-Type: text/plain Content-Length: 75 Last-Modified: Fri, 10 Jul 2009 20:11:52 GMT Connection: keep-alive Accept-Ranges: bytes Length: 75 [text/plain] 100%[====================================================================================>] 75 --.--K/s ''repo1'' protects itself from being cloned with ''wget''. See [[http://www.mail-archive.com/users@maven.apache.org/msg70362.html|here]] and [[codehaustracker>MRM-850|here]] for more information. ==== Artifact deployment ==== === How can I run embedded Web container? === See [[http://docs.codehaus.org/display/JETTY/Maven+Jetty+Plugin|maven Jetty plugin]]. Also see [[tomcat#quick_deployment_of_web_application|Quick deployment of Web application]]. === How to deploy to remote Tomcat? === We gonna use [[codehausmojo>tomcat-maven-plugin|Tomcat Maven Plugin]] for deployment. First we need to add the tomcat manager username and password to maven configuration file: local-server-id tomcat Ab1nXmI This user should have "manager" rights in Tomcat server config: ... Now we add the plugin to ''pom.xml'' for service (and for client, but changing the deployment context path): org.codehaus.mojo tomcat-maven-plugin local-server-id http://local-server.net:8080/manager /my-manager and use ''mvn tomcat:deploy'' or later ''mvn tomcat:redeploy''((See [[codehausmojo>tomcat-maven-plugin/context-goals.html|here]] the complete list of goals for this plugin)) to do the job: ... [INFO] ------------------------------------------------------------------------ [INFO] Building RDF Storage Web Service [INFO] task-segment: [tomcat:redeploy] [INFO] ------------------------------------------------------------------------ ... [INFO] [tomcat:redeploy] [INFO] Deploying war to http://local-server.net:8080/my-manager [INFO] OK - Undeployed application at context path /my-manager [INFO] OK - Deployed application at context path /my-manager [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ Your Tomcat instance should have [[tomcat>manager-howto.html|manager application]] running, as plugin communicates to Tomcat through that interface. === How to deploy to remote JBoss? === Currently neither [[codehausmojo>jboss-maven-plugin|jboss-maven-plugin]] nor [[http://www.jboss.org/maven-jboss-deploy-plugin/|maven-jboss-deploy-plugin]] allow to deploy the maven artifacts to remote JBoss AS. Look at [[http://cargo.codehaus.org/JBoss+Remote+Deployer|this page]] or [[codehaustracker>CARGO-416|this bug report]] for possible solutions. At the moment one of the reasonable solutions is ''scp'' the artifact to JBoss deploy directory (make sure you have ''org.jboss.deployment.scanner.URLDeploymentScanner'' bean enabled in ''conf/jboss-service.xml''). For example you can do it by binding to ''deploy'' phase so that artifact is deployed from CI server each time on successful build: maven-antrun-plugin 1.4 deploy run or artifact is deployed when you run ''mvn antrun:run'' manually: maven-antrun-plugin 1.7 ==== Releasing the project ==== For those, who want to make a release from a command line, I would refer them to look at [[http://maven.apache.org/plugins/maven-release-plugin/introduction.html|maven-release-plugin]] (see good reference [[http://maven.apache.org/guides/mini/guide-releasing.html|here]]). Here we will setup the following infrastructure: * Using [[http://nexus.sonatype.org/|Nexus]] as Maven repository manager((See [[http://docs.codehaus.org/display/MAVENUSER/Maven+Repository+Manager+Feature+Matrix|Maven Repository Managers Comparison Matrix]])) * Using [[https://hudson.dev.java.net/|Hudson]] as continuous integration system. So, what you need to do: * Make sure, that you have installed [[http://wiki.hudson-ci.org/display/HUDSON/M2+Release+Plugin|Hudson Maven Release Plug-in]] in Hudson plugin manager. * You have to enable plugin for specific project in project settings. Basic and sufficient is ''release:prepare release:perform -Dresume=false'' * In case you don't access SVN repository anonymously, you may wish to specify username/password, e.g. ''... -Dusername=john -Dpassword=nnn'' * To pass user-defined versions from Hudson Maven Release Plugin use ''... -DreleaseVersion=${RELEASE_VERSION} -DdevelopmentVersion=${DEVELOPMENT_VERSION}'' Unfortunately this plugin works only with Maven2 Hudson projects, adding support for freestyle projects is in TODO list. For freestyle Hudson projects you may use [[http://wiki.hudson-ci.org/display/HUDSON/Release+Plugin|Hudson Release Plugin]]. After this plugin is installed you need to configure "Before release step", which is simply invoking Maven with goals ''release:prepare release:perform -Dusername=john -Dpassword=abc123'': {{hudson_release_plugin.png|Hudson Release Plugin Settings}} If you need to pass version numbers from user, you need to wrap the call to maven into bash script as [[codehaustracker>MRELEASE-734|when releaseVersion and developmentVersion are passed in command-line but are empty they are not treated as not-defined]]. * ''maven-release-plugin'' will use ''project.scm.developerConnection'' (or ''project.scm.connection'' if the last one is not defined) to commit to source repository and ''project.distributionManagement'' for artifact deployment. So your ''pom.xml'' may look like this: 4.0.0 org.mycompany.project storage-service war 1.0-SNAPSHOT My Service scm:svn:https://localserver.com/svn/trunk/java/projects/myservice nexus-server-id http://mavenserver.com/nexus/content/repositories/releases nexus-server-id http://mavenserver.com/nexus/content/repositories/snapshots ... * After that you can make a release from Hudson project menu Sometimes the project build lifecycle generates logs, temporary files, which cause ''maven-release-plugin'' to complain with message ''Cannot prepare the release because you have local modifications''. To exclude these files from being checked use '''' or pass via CLI, e.g. ''-DcheckModificationExcludeList=.maven'' (see [[stackoverflow>9140315|How to disable maven release plugin check local modifications?]]). Some helpful information for maven release plugin: * [[http://www.nabble.com/Force-versions-plugin-to-remove-snapshots-td25192495.html#a25219813|information about how ''versions-maven-plugin'' works]] * [[codehaustracker>MRELEASE-35|release plugin doesn't tag correctly with svn+ssh when remote and local username don't match]] * [[codehaustracker>MRELEASE-293|Value of ${project.version} is captured before version resolution]] \\ Use ''@{project.version}'' instead. * [[codehaustracker>MRELEASE-128#comment-250968|SCM properties being replaced during release:perform]] \\ There is basically no workaround, as SCM properties are expanded by Maven and plugin sees already transformed values. Concerning multi-project release: * [[codehaustracker>MRELEASE-252#comment-170410-open|Support for multi modules project]] * [[codehaustracker>MRELEASE-261|release:prepare should support flat directory multimodule projects]] Books: * [[http://propellors.net/maven/book/index.html|MavenBook - Maven: The Definitive Guide (1.0 Alpha 2)]] * [[http://www.sonatype.com/books/mvnref-book/reference/|Maven Book: Maven: The Definitive Guide]] * [[http://www.sonatype.com/people/2009/10/maven-tips-and-tricks-advanced-reactor-options/|Maven Tips and Tricks: Advanced Reactor Options]] Other: * [[http://vaadin.com/wiki/-/wiki/Main/Using%20Vaadin%20with%20Maven|Using Vaadin with Maven]] === How to update parent POM to latest version just before the project POM is committed by ''release:prepare''? === You can do it using ''[[codehausmojo>versions-maven-plugin]]'' in combination with ''preparationGoals'' setting: maven-release-plugin 2.5.3 true versions:update-parent clean verify org.codehaus.mojo versions-maven-plugin 2.11.0 false === ''mvn release:prepare'' fails with message ''svn: OPTIONS of Server certificate verification failed: issuer is not trusted'' === You need to run the ''%%svn list ...%%'' command manually under the specified user (possibly, changing the user via ''sudo -u host_user -H /bin/bash''((''-H'' option is important, otherwise authentication information will be persisted in somebody's else ''~/.subversion/'' folder)) ), and then accept the server's certificate permanently((See also [[http://wiki.hudson-ci.org/display/HUDSON/Hosting+plugins#Hostingplugins-Releasingtohudson.dev.java.net|here]], [[http://osdir.com/ml/java.hudson.devel/2008-04/msg00141.html|here]] and [[http://www.nabble.com/Server-certificate-verification-failed:-issuer-is-not-trusted-td16755816.html#a16756364|here]] more discussions on authentication topics for ''maven-release-plugin'')). === ''mvn release:prepare'' fails with message ''svn: '/tags/java/project' path not found'' === This happens because plugin does not create parent path entries when tagging. See [[codehaustracker>MRELEASE-401|release:prepare should create the SVN tags parent dir if it doesn't already exist]] for more details. === Maven fails when executing plugin XXX with message ''Plugin XXX does not exist or no valid version could be found'' === Try the following: * check proxy settings (e.g. does your proxy requires NTLM authentication? haven't you got into [[codehaustracker>MNG-4394|proxy protocol trap]]?) * perform ''%%mvn -U ...%%'' (see [[http://docs.codehaus.org/display/MAVENUSER/FAQs-1#FAQs-1-novalidversion|FAQ]]) * if the group is amoung default ''org.apache.maven.plugins'' or ''org.codehaus.mojo'', then add to your ''settings.xml'' (see [[http://maven.apache.org/settings.html#Plugin_Groups|maven's documentation]]): org.mortbay.jetty === How to configure all SCM-dependant plugins to use native Java implementation to access SVN repository? === 2.0.5 1.7.8 ... maven-release-plugin ... com.google.code.maven-scm-provider-svnjava maven-scm-provider-svnjava ${maven.scm.svnjava.version} org.tmatesoft.svnkit svnkit ${svnkit.version} org.codehaus.mojo buildnumber-maven-plugin ... com.google.code.maven-scm-provider-svnjava maven-scm-provider-svnjava ${maven.scm.svnjava.version} org.tmatesoft.svnkit svnkit ${svnkit.version} {{tag>maven hudson release}}