I have a project that consist of 3 different libraries. When I run install script it takes all libraries from repo and run mvn clean install on them. But this version of library already installed in repo. Is there a way to skip install phase if version in pom.xml equal version in my local repo.
I know that I can use local repo and just set dependencies. But my boss want that our project can build only with public repos and without any our repos.
You can bypass like this
-Dmaven.install.skip=true
<profiles>
<profile>
<id>skipInstall</id>
<activation>
<property>
<name>maven.install.skip</name>
<value>true</value>
</property>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<executions>
<execution>
<id>default-install</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
Last week Olivier Lamy patched this jira.
MINSTALL-73
Most maven plugins can be skipped by specifying something like:
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>X.Y</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
you can also set up build profiles to set properties and use that to determine the value. for example, running the command: mvn -Pexample would select the "example" profile. The POM would then contain:
...
<properties>
<skip.install>false</skip.install>
...
</properties>
...
<profile>
<id>example</id>
<properties>
<skip.install>false</skip.install>
</properties>
</profile>
...
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>X.Y</version>
<configuration>
<skip>${skip.install}</skip>
</configuration>
</plugin>
...
Using these POM additions, the default behavior for the install plugin will be to perform its default goal, but if the example profile is selected, then the install plugin will skip its goal.
Using what I learned from the other answers, this was the cleanest result for me.
In my super pom I added a pluginManagement/plugin to disable default-install and default-test phases when the property deployOnly is set.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
<executions>
<execution>
<id>default-install</id>
<configuration>
<skip>${deployOnly}</skip>
</configuration>
</execution>
<execution>
<id>default-test</id>
<configuration>
<skip>${deployOnly}</skip>
</configuration>
</execution>
</executions>
</plugin>
So on the command line, I can disable install and test phases by adding -DdeployOnly.
mvn clean install #build and test everything
mvn deploy -DdeployOnly #just deploy it
I know that I can use local repo and just set dependencies. But my boss want that our project can build only with public repos and without any our repos.
Are you sure you understood correctly what you boss meant? I interpret the above as "don't install third party libraries in your local repository, use only libraries available in public repositories". This is different from "don't use your local repository" which is basically impossible, that's just not how maven works. I'd try to clarify this point.
Apart from that, I don't get the question which is very confusing (what repo are you talking about? What is the install script doing? Why do you call clean install on libraries? etc).
Extending the other answers, from the future.
Maven plugins have a surprisingly high freedom, how do they run. If they want, they can ignore/override the typical pom.xml settings. Furthermore, also the <configuration><skip>true</skip></configuration> is only a convention, nothing obligates a plugin to follow it, except that most of them is developed so.
My experiments with the recent problem show, that both #Cemo's and #MiloshBoroyevich solution should be utilized, also the plugin requires both to really let us in peace. More concretely, the only working configuration by me was this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
<executions>
<execution>
<id>default-install</id>
<phase>none</phase>
</execution>
</executions>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
One of your options is to put the deployment to another module. I.e. have one pom.xml build the artifact and install it to the local repo, and another pom.xml to deploy it. This separation is quite common in larger projects, where the testsuite is sometimes a separate module or even a project, the packaging happens in several stages, etc.
- pom.xml - myProject-root - type=pom
- pom.xml - myProject-artifact - type=jar
- pom.xml - myProject-deploy - type=pom, does the deployment, skips it's own `install` goal
I have a War file that has dependencies and class files that I need in it that I am trying to include in my project with Maven. Inside the War file, there is a WEB-INF that contains those libs and classes. I have tried everything that I know to try to get this going, but my knowledge of Maven is limited.
I have tried simply listing the War as a dependency and following the process described here to install the third-party library, but when I do that Maven says it can't find my packages that I need when I try to install.
I have tried overlaying the War as described here with no luck.
I have tried maven-warpath-plugin but didn't really have any luck either.
Should any of these tools solve my problem? Is how I am trying to solve the problem possible in this way? Or am I completely off base?
Here are the important parts of my pom.xml from using the maven-warpath-plugin:
<build>
...
<pluginManagement>
<plugins>
<plugin>
<groupId>org.appfuse</groupId>
<artifactId>maven-warpath-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<extensions>true</extensions>
<executions>
<execution>
<goals>
<goal>add-classes</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
...
</build>
<repositories>
<repository>
<id>data-local</id>
<name>data</name>
<url>file://${project.basedir}/o</url>
</repository>
</repositories>
<dependencies>
...
<dependency>
<groupId>my.local.dep</groupId>
<artifactId>MyLocalDep</artifactId>
<version>1.1.1.1</version>
<type>war</type>
</dependency>
<dependency>
<groupId>my.local.dep</groupId>
<artifactId>MyLocalDep</artifactId>
<version>1.1.1.1</version>
<type>warpath</type>
</dependency>
</dependencies>
Unpack the war in a separate clean step first and add the unpacked jars as system dependency in the main step.
Idea is from here: https://stackoverflow.com/a/6120395/503025
I have multi-module maven project. I can see generated project dosumentation after mvn site, but it is in every module target folder.
how to get maven project site into one folder?
(I don't really need to deploy, I will put generated site manually into GitHub pages.)
Plugin docs:
http://maven.apache.org/plugins/maven-site-plugin/
References <distributionManagement> <site> section, but there is no trace how to make output into a defined folder.
Also tried mvn site:jar - it make .jar again in every module target.
I would recommend to use the site-maven-plugin following part to distribute generated sites to github:
<profile>
<id>github</id>
<build>
<plugins>
<plugin>
<groupId>com.github.github</groupId>
<artifactId>site-maven-plugin</artifactId>
<version>0.8</version>
<configuration>
<message>Creating site for ${project.version}</message>
<server>github</server>
</configuration>
<executions>
<execution>
<goals>
<goal>site</goal>
</goals>
<phase>post-site</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
To preview your site before publishing you can use the stage goal of maven-site-plugin like this:
mvn site:stage -DstagingDirectory=C:\fullsite
We hava a new project friend and we want to install the project to his enviroment. But there are too many dependencies that not exists in the maven repository. So maven became useless. We installed an archiva server to install our artifacts there, but we dont want to deploy all that dependencies one by one(not only project jar self, all the dependencies). Is there an automated solution for this situation?
Thanks in advance.
Initially if you tweak your projects pom.xml and add:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>localrepo</outputDirectory>
<useRepositoryLayout>true</useRepositoryLayout>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
and run mvn package this should create a copy of your dependencies in repository directory format inside the localrepo directory (I tried using the command line options to dependency:copy-dependencies but it wouldn't work for me). Now comment out the above from your pom.xml as you probably don't need it anymore.
I've never used Archiva but I imagine at this point you could install the localrepo repository files onto a local web server and configure your Archiva server to mirror it.
Alternatively, if you wanted to produce a minimal effort install for your end user (and distribution size wasn't an issue) you could include this localrepo directory in your distribution and provide maven with a reference to it by adding the following to your pom.xml:
<repositories>
<repository>
<id>local-repo</id>
<name>local-repo</name>
<url>file://${basedir}/localrepo</url>
<releases>
<enabled>true</enabled>
<checksumPolicy>ignore</checksumPolicy>
<updatePolicy>always</updatePolicy>
</releases>
</repository>
</repositories>
This local repository technique is very useful when distributing home grown and 3rd party jar files that are not in public Maven repositories. You can always remove the libraries that are in public repositories.
I find nothing discourages new users from Maven quicker than my trying to explain all that mvn install:install-file palaver that is usually necessary to install 3rd party jars (however enthusiastic I may be about Maven).
I am developing application that uses Cassandra NoSQL database and I am adding web interface. I have 2 projects: cassandra-access (this project is DAL) and web (this project is web application).
Scenario is simple enaugh. Cassandra-access has dependencies on hector.jar which is not in maven repository. So I added this dependency to my local repository via mvn install:install-file and I list my repository in parent pom:
<repositories>
<repository>
<id>loc</id>
<url>file://${basedir}/../mvn-local-repository</url>
</repository>
</repositories>
In Web projects pom I added dependency on Cassandra-access. But when i start the Web application with hello world read from database I am getting classNotFound exception as if the hector.jar isn't on class path. When I write mvn clean install the resulting war of web project doesn't include hector.jar in WEB-INF/lib. That further confirms my theory.
How to achieve that war get's all the transitive dependcies? I thought that all dependencies that are in scope compile (which is default) will get copied.
Web projects pom:
<dependency>
<groupId>net.product</groupId>
<artifactId>cassandra-access</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
Cassandra-access pom:
<dependency>
<groupId>me.prettyprint</groupId>
<artifactId>hector</artifactId>
<version>0.7.0</version>
</dependency>
It maybe not the optimal solution but it works for me:
put the hector jar in the lib directory of the cassandra access.
add to the cassandra-access pom:
<dependency>
<groupId>%HECTOR_JAR_GROUP_ID%</groupId>
<artifactId>%HECTOR_JAR_ARTIFACT_ID%</artifactId>
<version>%HECTOR_JAR_VERSION%</version>
<scope>system</scope>
<systemPath>${basedir}/lib/%HECTOR_JAR_NAME%</systemPath>
</dependency>
then add the following plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>