I developed a maven plugin to install the missing jars that cannot be found in central repository but can be found in local file system,i attach the goal to pre-clean phase and when i execute command "mvn clean compile", the plugin is not executed, instead i got the following error:
i suppose the missing jar in the error is installed firstly and then compile phase is executed. However, the error indicates dependency should be resolved firstly.
PS:
here is the config of my plugin in pom.xml:
Related
I'm using Maven for my project. It is not an issue if my project doesn't use some local resources.
So that I'm following this guide
https://stackoverflow.com/a/61576687/6720896
to copy my local jar to local maven repository and validated by Maven.
As you can see, in the maven-install-plugin, I'm setting to install local repository at clean phase.
It means by mvn clean, maven will copy my jar to maven local repository.
The problem is, if I run mvn clean and mvn install by two commands separately => there is no problem
If i run mvn clean install => the build is failed as the log
Caused by: org.apache.maven.project.DependencyResolutionException: Could not resolve dependencies for project xxxx:xxxx:war:0.0.1-SNAPSHOT: Failure to find org.xxxx:xxxx-ws:jar:1.0.0 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced
Seem like by default, maven always execute following order: validate > compile > clean > install. I also tried with 'mvn clean validate' but the error still occurs.
Thank you for reading.
The question is not really clear, but my interpretation is as follows:
The OP wants to automatically add a dependency to the local repository by using install:install-file. Then the OP wants to use that dependency. This works if mvn clean and mvn install are run separately, but not if one runs mvn clean install.
The reason is as follows:
Maven resolves dependencies at the beginning of the process. So dependencies are already resolved before the clean of mvn clean install is executed.
This especially implies that you cannot install and resolve a dependency in the same Maven run.
If, though, you first run mvn clean (which installs the dependency) and then mvn install (which uses the dependency), everything is fine.
I am using the Tycho plugin to compile an Eclipse plugin project. When I run the command
mvn clean install my build passes
When I run the command
mvn clean verify install my build fails with the following:
[ERROR] Failed to execute goal org.eclipse.tycho:tycho-p2-plugin:1.1.0:
p2-metadata-default (default-p2-metadata-default) on project
com.mysite.project:
Execution default-p2-metadata-default of goal
org.eclipse.tycho:tycho-p2-plugin:1.1.0:p2-metadata-default failed.
IllegalArgumentException -> [Help 1]
The failure stacktrace is:
at org.eclipse.tycho.p2.impl.publisher.P2GeneratorImpl.getCanonicalArtifact(P2GeneratorImpl.java:193)
at org.eclipse.tycho.p2.impl.publisher.P2GeneratorImpl.generateMetadata(P2GeneratorImpl.java:146)
at org.eclipse.tycho.plugins.p2.P2MetadataMojo.attachP2Metadata(P2MetadataMojo.java:149)
at org.eclipse.tycho.plugins.p2.P2MetadataMojo.execute(P2MetadataMojo.java:108)
at org.eclipse.tycho.plugins.p2.P2MetadataDefaultMojo.execute(P2MetadataDefaultMojo.java:33)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
... 21 more
From everything I can find on Maven, invoking the install phase should implicitly trigger the verify phase. What's going on here?
personally, i never use mvn install when using tycho, because it will install the bundles into your local repo, and since you're build eclipse bundles, you do not have to push them to your maven repo.
back to your question, calling two phases in a single command is not necessary since the install phase should trigger the verify phase.
so use only mvn verify to build your product or only mvn install to achieve the exact same goal ( and have the built artifact pushed into your local repo )
I am trying to setup Jenkins to automate project builds and I ran to the following problem. mvn clean install works perfectly from cmd but project build from jenkins fails when maven-antrun-plugin is being used.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.7:run
(clientgen) on project Sample:
An Ant BuildException has occured: Compile failed; see the compiler error output for
details.
[ERROR] around Ant part ...<javac fork="yes" memoryInitialSize="512m"
destdir="E:\Jenkins\workspace\Trunk Builds\Sample\target/generated-sources"
memoryMaximumSize="1024m" srcdir="E:\Jenkins\workspace\Trunk Builds\Sample\target/build"
source="1.4" classpathref="maven.plugin.classpath" executable="C:\j2sdk1.4.2_19/bin/javac"
target="1.4"/>... # 46:428 in
E:\Jenkins\workspace\Trunk Builds\Sample\target\antrun\build-main.xml
Jenkins is actually unable to check for the packages imported when I use maven-antrun-plugin.
[javac] E:/Jenkins/workspace/Trunk Builds/Sample/target/build/ClassSample.java:20:
package org.sample.package does not exist
Whenever I do not use maven-antrun-plugin Jenkin build succeeds. Any ideas why even though it works through cmd jenkins fail to build the project?
Actually I found the real problem and found a workaround. The problem is that Jenkins did not access .m2/repository for some reason so I configured Jenkins to use local to workspace repository. Now it builds normally.
We have a process to update part of a build that is not in Maven yet but will be soon. Once built, we manually put the jar in Nexus and then update the pom files that are in SVN. Works fine and doing a "mvn clean install" pulls down the new .jar and creates a new folder in my local repository etc. Grand.
Now I would like to be able to get any new version that has been uploaded by making a mvn call without doing a build (as with mvn install). I was looking at mvn dependency:get but it seems to have a lot of parameters that only gave me errors.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.1:get(default-cli) on project workflow-project: The parameters 'repositoryUrl' for goal org.apache.maven.plugins:maven-dependency-plugin:2.1:get are missing or invalid -> [Help 1]
I have tried adding the mentioned repositoryUrl param but it too gives me errors, not least about deprecation. Is this the correct goal? How is it most simply used if so?
Use the Maven Versions plugin. It has a ton of useful commands for managing dependency versions in a POM.
For example, you can run the following:
mvn versions:use-latest-versions
That command will replace versions in your POM with the latest version of artifacts. There are optional parameters you can pass to have more fine-grained control. For example, you can use the includes parameter to specify a particular artifact to update to the latest version.
Perhaps you would be happy with a
mvn compile
Which would load the dependencies and compile but go no futher. The only changes would be in target
I'm working on a multimodule maven project. Some time ago, the project was partitioned into subprojects:
"Common" JAR project
"User" WAR project, depending on Common
etc.
It's the same project as described here, in this question.
When I invoke mvn package at superproject level, command succeeds and resulting war can be deployed. But if I try to invoke mvn package at subproject level, command fails.
[ERROR] Failed to execute goal on project User: Could not resolve
dependencies for project xxx.xxx:User:war:0.0.1-SNAPSHOT: Failed
to collect dependencies for [xxx.xxx:Common:jar:0.0.1-SNAPSHOT (compile), ...
Apparently maven is trying to download my own project (Common) from remote repo...
Downloading: http://repository.jboss.org/maven2/xxx/xxx/Common/0.0.1-SNAPSHOT/maven-metadata.xml
Downloading: http://download.java.net/maven/glassfish/xxx/xxx/Common/0.0.1-SNAPSHOT/maven-metadata.xml
[WARNING] Could not transfer metadata xxx.xxx:Common:0.0.1-SNAPSHOT/maven-metadata.xml from/to jboss (http:/
/repository.jboss.org/maven2): Access denied to: http://repository.jboss.org/maven2/xxx/xxx/common/0.0.1-SNA
PSHOT/maven-metadata.xml
What could possibly be wrong in my config?
When you run mvn package from superproject, it creates the artifacts in the respective target folder, but does not install them in your local repository.
So, when you run mvn package on a subproject, which has a dependency on a sibling module, it looks for the dependency in your local repository, does not find it and thus attempts to download it from the various repositories configured.
Once you successfully run an mvn install from superproject, an mvn package on the subproject should work.
You have a (JBoss) repository entry either in your pom.xml or settings.xml.
To access this repository it is required to be authenticated. If you call the path with your browser, you get also "403 Forbidden". You have to add a public repository of Jboss. (http://repository.jboss.org/)
I have spent a lot of time to find out this sort of 'ERROR', thanks to Raghuram, I was stupid when trying to find the solution but there was actually no error, just because I did mvn install in a submodule which depends on dependencies of other modules, It should work fine when i run mvn install/package on parent scope.