Mvn clean no dependencies

I have a third-party bank, which is necessary for our project. It is not available in the maven central repository, so I used maven-install-plugin to install the jar locally during build. I linked the install-file target to the validate phase and this basically works. Below you will find a fragment of the pom.xml file:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> ... <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-install-plugin</artifactId> <version>2.3</version> <executions> <execution> <id>install-myartifact</id> <phase>validate</phase> <goals> <goal>install-file</goal> </goals> <configuration> <file>${basedir}/lib/myartifact-1.2.3.jar</file> <groupId>com.example</groupId> <artifactId>myartifact</artifactId> <version>1.2.3</version> <packaging>jar</packaging> <generatePom>true</generatePom> </configuration> </execution> </executions> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>com.example</groupId> <artifactId>myartifact</artifactId> <version>1.2.3</version> </dependency> </dependencies> 

However, there is a catch. Most of our developers and our Jenkins installation run "mvn clean install". The “verify” phase is not part of the “clean” life cycle, and the clean phase inexplicably requires all the dependencies to run. Therefore, the first time someone starts this assembly, it does not work.

 [INFO] Scanning for projects... [INFO] ------------------------------------------------------------------------ [INFO] Building MyModule [INFO] task-segment: [clean, install] [INFO] ------------------------------------------------------------------------ [INFO] [clean:clean] [INFO] Deleting directory C:\svn\trunk\mymodule\target Downloading: http://nexusserver.local:8080/nexus/content/groups/public/com/example/myartifact-1.2.3.pom [INFO] Unable to find resource 'com.example:myartifact:pom:1.2.3' in repository central (http://central) [INFO] ------------------------------------------------------------------------ [ERROR] BUILD ERROR [INFO] ------------------------------------------------------------------------ [INFO] Failed to resolve artifact. Missing: ---------- 1) com.example:myartifact:jar:1.2.3 Try downloading the file manually from the project website. Then, install it using the command: mvn install:install-file -DgroupId=com.example -DartifactId=myartifact -Dversion=1.2.3 -Dpackaging=jar -Dfile=/path/to/file Alternatively, if you host your own repository you can deploy the file there: mvn deploy:deploy-file -DgroupId=com.example -DartifactId=myartifact -Dversion=1.2.3 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id] Path to dependency: 1) com.example:mymodule:war:0.0.1-SNAPSHOT 2) com.example:myartifact:jar:1.2.3 ---------- 1 required artifact is missing. for artifact: com.example:mymodule:war:0.0.1-SNAPSHOT from the specified remote repositories: nexus (http://nexusserver.local:8080/nexus/content/groups/public) [INFO] ------------------------------------------------------------------------ [INFO] For more information, run Maven with the -e switch [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1 second [INFO] Finished at: Thu Jun 09 11:01:24 EDT 2011 [INFO] Final Memory: 17M/247M [INFO] ------------------------------------------------------------------------ 

If I just ran "mvn install", the jar was installed during the "check", and I can run "mvn clean install" in subsequent builds. However, our build server does not have this flexibility. I reviewed the following:

  • Moving the phase to “pre-clean”, but it is assumed that everyone always uses the clean-up for the first time. This would not help if someone just “installed mvn”.
  • Copying of the performance, one of which occurs during the "preliminary cleaning" and one occurs during the "check". This covers all bases, but the copied code leaves a bad taste.

Ideally, I would like another option. Is it possible to work without any dependencies? Or run the plugin twice without a full copy of the execution? Thanks!

+6
source share
4 answers

It looks like you are using nexus. It might be easier to deploy the artifact to the nexus repository rather than support it with this project.

+5
source

I had a problem with this, and I found this question when I was looking for a solution to solve the problem, so I will focus on this:

mvn clean fails in a multi-module project when there are no invalid dependencies in one project if plugins are called during cleaning.

We call the antrun-plugin during the clean phase in some modules, and because of this, all the dependencies must be present in the maven repository, including other modules in the same reactor, which in some cases have not yet been built (let's say you just pounced to the project version, or you are starting a new project).

This is a maven-antrun error, which is reported at http://jira.codehaus.org/browse/MANTRUN-78 , which again leads to an error in the maven kernel: http://jira.codehaus.org/browse/MNG-3283 .

My workaround was to provide developers (and Jenkins) with an alternative way to do clean (shell / bat script, ant script, or some git / hg clean operations) and make them call it instead.

I would suggest a similar workaround for your team (or just set up a common maven repository inside your team, if necessary, use one of the development machines).

+5
source

This is unchecked, but can you ignore the error from a pure plugin configuration? How in:

 <plugin> <artifactId>maven-clean-plugin</artifactId> <version>2.4.1</version> <configuration> <failOnError>false</failOnError> </configuration> </plugin> 

(This is from Maven Clean Plugin: ignoring clean errors )

0
source

Here is another opportunity.

Configure maven to skip the clean phase and start the cleanup during initialization. Did not try this though.

The disadvantage of this is that maven will always clear the output folders.

0
source

Source: https://habr.com/ru/post/890157/


All Articles