Copy all output jars with dependencies into one folder - maven-3

I've got a parent POM.xml defining 4 modules, 3 of which reference the first one (this project to be precise).
I am trying to copy all output jars with their runtime dependencies into one folder using the following commands:
mvn package
mvn org.apache.maven.plugins:maven-dependency-plugin:3.1.1:copy-dependencies
-DoutputDirectory=deps -DincludeScope=runtime
-DexcludeGroupIds=com.acadiasoft.im
The first command succeeds and the last fails with the error:
[ERROR] Failed to execute goal on project simm: Could not resolve dependencies for project com.acadiasoft.im:simm:jar:1.0.0-SNAPSHOT: Could not find artifact com.acadiasoft.im:base:jar:1.0.0-SNAPSHOT -> [Help 1]
Note the last parameter -DexcludeGroupIds=com.acadiasoft.im which is how I tried working around this error. I also tried excludeArtifactIds to the same effect.
Question 1: Why doesn't it work? Why is it not skipping artefacts with group id com.acadiasoft.im?
Question 2: Is there a way to make maven 'see' the the jars produced in the mvn package step and copy them over along with their dependencies?
Version info:
Maven 3.6.1
JDK 1.8
Please note that I would prefer a command line based solution rather than having to modify a POM. Thanks.

working spell is
mvn clean install
mvn org.apache.maven.plugins:maven-dependency-plugin:3.1.1:copy-dependencies -DoutputDirectory=deps -DincludeScope=runtime -DexcludeGroupIds=com.acadiasoft.im
note package -> install

Related

Implicit dependency to json-lib-2.4-jdk15.jar causes build to fail, even though it's been excluded in build.gradle

I'm converting an existing Maven based project containing a Grails 2.4.2 application to Gradle 2.6 and Grails 3.0.4. It's a mixed environment with Java, Groovy, and Grails used in several sub-projects. I've converted all the pom.xml files into build.gradle files, starting off with ./gradlew init, and then hand editing as needed. Before converting the Grails project's grails-app/conf/BuildConfig.groovy to the build.gradle equivalent, everything built fine with Gradle 2.6. After I converted the Grails project's BuildConfig.groovy file to build.gradle, I'm getting the following error when trying to run ./gradlew build:
FAILURE: Build failed with an exception.
* What went wrong:
Could not resolve all dependencies for configuration ':foo:runtime'.
> Could not find json-lib-jdk15.jar (net.sf.json-lib:json-lib:2.4).
Searched in the following locations:
file:/Users/xyz/.m2/repository/net/sf/json-lib/json-lib/2.4/json-lib-2.4-jdk15.jar
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
The json-lib-2.4.jar file does exist in the local M2 cache shown above, but it doesn't have the -jdk15 part in it. There's no explicit dependency to any json-lib jar file in the build.gradle file for the Grails project. A parallel project does have an explicit dependency on this library, but that project builds fine. I've tried to explicitly add the dependency to the build.gradle file in the Grails project both with and without "classifier: 'jdk15'" to the dependency declaration. When I ran ./gradlew dependencies, I noticed that an older version (2.3) of the json-lib jar file showed up in the list as an implied dependency for some Apache HttpComponent stuff. I then tried both versions of this in the allProjects section of the top level build.gradle:
configurations {
all*.exclude module: 'json-lib'
}
as well as:
configurations {
all*.exclude module: 'json-lib', classifier: 'jdk15'
}
Neither variant makes any difference. I'm really stuck on this and would appreciate any tips on how to move forward. In case it makes a difference, I'm running this on a Mac with MacOS 10.10.5, the JDK version is 1.8.0_25-b17. Thanks.
dependencies {
//compile group: 'net.sf.json-lib', name: 'json-lib', version: '2.4'
compile "net.sf.json-lib:json-lib:2.4:jdk15"
}

Getting Error in POM.xml on KEPLER Eclipse

I have created maven based web application so after created application i am getting two errors in pom.xml which are
1.Multiple annotations found at this line:
- Failure to transfer org.apache.maven.plugins:maven-resources-plugin:pom:2.6 from http://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. Original error: Could not transfer artifact org.apache.maven.plugins:maven-resources-plugin:pom:2.6 from/to central (http://
repo.maven.apache.org/maven2): null to http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-resources-plugin/2.6/maven-resources-plugin-2.6.pom
2.Multiple annotations found at this line:
- Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile (execution: default-testCompile, phase: test-compile)
- Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (execution: default-compile, phase: compile)
- CoreException: Could not calculate build plan: Plugin org.apache.maven.plugins:maven-compiler-plugin:3.1 or one of its dependencies could not be resolved: Failed to read artifact descriptor for
org.apache.maven.plugins:maven-compiler-plugin:jar:3.1: ArtifactResolutionException: Failure to transfer org.apache.maven.plugins:maven-compiler-plugin:pom:3.1
Could you please let me know what needs to be done for resolving the issue
If you are facing the same issue I described in my comment above then it seems I could fix it by running mvn eclipse:eclipse with working directory set to Eclipse project folder i.e.
$ cd /path/to/eclipse/workspace/Project
$ mvn eclipse:eclipse
Does this work for you ? Maybe your environment is different . Providing more details might help others to understand your problem even better so as to offer useful suggestions .
I had similar problem Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile (execution: default-testCompile, phase: test-compile).
To Fix (apart from installing M2E plug-in and all):
Ensure installed maven is > 3.1 (using mvn -v). If not, you need to upgrade.
Ensure eclipse is pointing to correct maven location (Window->Preferences->Maven->Installations)
On Command prompt, go to project home directory and run mvn eclipse:clean and mvn eclipse:eclipse
Disable and enable Maven nature in eclipse (Right click on project, goto Maven -> Disable Maven Nature. To enable, Right click on project goto Configure -> Convert to Maven Project)

Error "The goal you specified requires a project to execute but there is no POM in this directory" after executing maven command

I have a pom.xml in C:\Users\AArmijos\Desktop\Factura Electronica\MIyT\componentes-1.0.4\sources\pom.xml and I executed:
mvn install:install-file -DgroupId=es.mityc.jumbo.adsi -DartifactId=xmlsec-1.4.2-ADSI -Dversion=1.0 -Dpackaging=jar -Dfile=C:\Users\AArmijos\Desktop\Factura Electronica\MIyT\componentes-1.0.4\core\xmlsec-1.4.2-ADSI-1.0.jar
however it returned the error below:
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.310s
[INFO] Finished at: Thu May 02 16:48:29 COT 2013
[INFO] Final Memory: 2M/15M
[INFO] ------------------------------------------------------------------------
[ERROR] The goal you specified requires a project to execute but there is no POM
in this directory (C:\Users\AArmijos). Please verify you invoked Maven from the
correct directory. -> [Help 1]
Can someone explain why it fails?
This link helped: https://stackoverflow.com/a/11199865/1307104
I edit my command by adding quotes for every parameter like this:
mvn install:install-file "-DgroupId=org.mozilla" "-DartifactId=jss" "-Dversion=4.2.5" "-Dpackaging=jar" "-Dfile=C:\Users\AArmijos\workspace\componentes-1.0.4\deps\jss-4.2.5.jar"
It's worked.
For any of those who are experiencing this on Windows and none of the above worked, try running this from cmd.exe. Executing these commands via PowerShell caused the install to fail each time.
On Windows when you are using PowerShell you have to enclose all parameters with quotes.
So if you want to create a maven webapp archetype you would do as follows:
Prerequisites:
Make sure you have maven installed and have it in your PATH environment variable.
Howto:
Open windows powershell
mkdir MyWebApp
cd MyWebApp
mvn archetype:generate "-DgroupId=com.javan.dev" "-DartifactId=MyWebApp" "-DarchetypeArtifactId=maven-archetype-webapp" "-DinteractiveMode=false"
Note: This is tested only on windows 10 powershell
Adding one more answer for Windows users. If none of this solves the problems.
Do not add space before or after =
-DgroupId= com.company.module //Wrong , Watch the space after the equal to
-DgroupId=com.company.module //Right
Its better to put everything inside double quotes, like "-DgroupId=com.."
This will give you exact error rather than some random error.
Weird that , maven does not even care to mention this in the documentation.
In my case, its because I copied pasted the command from the browser and it turned out that the dash was not the ASCII dash, just delete and type the dash again.
http://www.toptip.ca/2017/04/maven-most-weird-error-causing-failure.html
I was trying to install java jms-1.1.jar after downloading a copy from jboss repository.
Encountered exact same error and specifically on windows. Tried everything i.e. changed maven version / jdk version but no avail.
I was using the command below .
mvn install:install-file -DgroupId=javax.jms -DartifactId=jms -Dversion=1.1 -Dpackaging=jar -Dfile=jms-1.1.jar
Finally took a que from the comment in the main question and put every parameter value within double quotes
mvn install:install-file -DgroupId="javax.jms" -DartifactId="jms" -Dversion="1.1" -Dpackaging="jar" -Dfile="jms-1.1.jar"
This solved the problem. The issue seems very specific to windows environment. On ubuntu and mac the command works without any issues.
Totally true (When using PowerShell you need to put quotes). When I run the command and put quotes around the parameters that have a dot, it works. Instead of typing 1.4, you should type "1.4"
First time:
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false
Error:
[ERROR] The goal you specified requires a project to execute but there is no POM in this directory (C:\Users\jcrojas\OneDrive - Superfinanciera\Personal\Aprendizaje\Maven\test). Please verify you invoked Maven from the correct directory. -> [Help 1]
Second time:
mvn archetype:generate -DgroupId="com.mycompany.app" -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion="1.4" -DinteractiveMode=false
...BUILD SUCCESS...
The command also works if it is run with the Windows command line, CMD. In this case, the quotation marks are not necessary.
Changing mvn clean to mvn clean --file *.pom fixed this issue for me.
On Windows, I got this error when running under a non-administrator command prompt. When I ran this as administrator, the error went away.
1.create a lib folder in your project file,
2.copy your jarFiles to the lib folder
3.right click on to your jarFile go to build path>Add to build path (now your jar file is part of your refrerenced libraries )
4.open command prompt and navigate to your project directory and write
mvn install: install-file "-Dfile=<yourJarFileName>.jar" "-DgroupId=<yourGroupID>" "-DartifactId=<yourArtifactId>" "-Dversion=<yourVersion>" "-Dpackaging=jar"
6.Rebuild your local repository index by opening in eclipse-
go to window>show view>other>maven>maven Repositories.
Right click on local Repositores and hit "RebuildIndex"
5.open your pom.xml file and add your dependency
<dependency>
<groupId><yourGroupID></groupId>
<artifactId><yourArtifactId></artifactId>
<version><yourVersion></version>
</dependency>
and run
mvn clean
mvn compile
mvn test
I got this error suddenly in Netbeans (but it worked from the command line) and it turns out some other program had changed the default directory of the command prompt. And because Netbeans runs "cmd /c" when invoking maven, it starts in an incorrect directory.
Check out in Regedit the value for
HKEY_CURRENT_USER\Software\Microsoft\Command Processor\Autorun
If it has been set, you probably should remove it to fix the problem. (1)
(I landed here when trying to resolve this issue, might not be 100% applicable to the current question - but might help others)
(1)
Changing default startup directory for command prompt in Windows 7
The execution of maven command required pom.xml file that contains information about the project and configuration details used by Maven to build the project. It contains default values for most projects.
Make sure that porject should contains pom.xml at the root level.
Add the Jenkinsfile where the pom.xml file has present.
Provide the directory path on dir('project-dir'),
Ex:
node {
withMaven(maven:'maven') {
stage('Checkout') {
git url: 'http://xxxxxxx/gitlab/root/XXX.git', credentialsId: 'xxxxx', branch: 'xxx'
}
stage('Build') {
**dir('project-dir') {**
sh 'mvn clean install'
def pom = readMavenPom file:'pom.xml'
print pom.version
env.version = pom.version
}
}
}
}
There may be a problem with Maven path configuration, if you used unix-like Operator System.
step 1: create new file in path ~/.bash_profile
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home
CLASSPAHT=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
PATH=$JAVA_HOME/bin:$PATH:
export JAVA_HOME
export CLASSPATH
export PATH
step 2: shell run source ~/.bash_profile OR modify zsh config file(add new line: source ~/.bash_profile)
Just watch out for any spaces or errors in your arguments/command. The mvn error message may not be so descriptive but I have realised, usually spaces/omissions can also cause that error.
I just added the path to the pom.xml as such
mvn -f path/to/pom.xml <goals> ...
Worked great for me
There could be some special characters added to your command like the '-' U+2013 and U+002d
Please remove the special characters and try the command
"The goal you specified requires a project to execute": The answer is in your question. I faced the same issue. Run the "mvn command" within the project folder, Also make sure sure its a maven configured project and hence contains the "POM.xml" file and you should be good to go!
Check for the name of the file, i.e pom.xml file is spelled correctly with proper file extension .xml.
Example for this error are
pom.ml
pm.xl
Please run it from the directory where POM.XML resides.

PluginVersionResolutionException in maven

In my system previously C:\Users\abc after changed as C:\Users\xyz now the problem while running the maven with "mvn clean install" it rises exception as LocalRepositoryNotAccessibleException,it takes previous path "C:\Users\abc" but its not there in my system bcz i alreay changed to "C:\Users\xyz".And .m2 folder is not there in my C:\Users\xyz path so i explicitly given in settings.xml localrepository location as "C:\Users\xyz.m2\repository" now .m2 localrepository created above problem solved.But now another i faced another problem is i run command "
mvn clean install" it shows "PluginVersionResolutionException" but it recognize the correctly C:\Users\xyz but shows this exception.I check the plugin versions in my files correctly i specified.Please give me the solution and explain why it behaves like this?
Thanks
This means that you have defined a plugin dependency in your pom without specifing the version of the plugin.
As you have not specify the error message, I give you an example, an let you fix you own bug.
This is an example :
1/ I suppose that I execute the maven command > mvn intall -X
2/ in the console I have the folowing error :
[ERROR] Error resolving version for plugin 'org.codehaus.mojo:findbugs-maven-plugin' from the repositories ...
org.apache.maven.plugin.version.PluginVersionResolutionException: Error resolving version for plugin 'org.codehaus.mojo:findbugs-maven-plugin' from the repositories ...
3/ The error seems to be located in "findbugs-maven-plugin" dependency
4/ I go to my pom.xml file, and I search the dependency to the plugin, I will find that I haven't specified the version of the plugin. So I add it and it will be resolved
like this :
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.5.3</version> ==> I add this line to fix the pb
</plugin>

How to make Maven install submodule poms?

I have a project that is building fine on my laptop. Today I started to set up the build for this on our Bamboo server. Everything is checked in. Both my laptop and the build server are using Maven 3.0.4.
I have a top-level aggregator pom that specifies several modules, but this pom is not the parent of any module. I do use parent poms, but those parents are in peer submodules of the submodules that depend on them, and I have blank "relativePath" elements in all poms.
In the Bamboo build of the top-level aggregator POM, I see several errors like this:
[ERROR] The project com.example.cde:java-project-parent:1.0.1 (/volatile/bamboo/bamboo3.4.3_data/xml-data/build-dir/FOO-BUILD-JOB1/java-project-parent/pom.xml) has 1 error
18-Dec-2012 16:40:21 [ERROR] Non-resolvable parent POM: Failure to find com.example.cde:project-parent:pom:1.0.0 in http://hostname.net:8081/nexus/content/groups/stuff was cached in the local repository, resolution will not be reattempted until the update interval of nexus has elapsed or updates are forced and 'parent.relativePath' points at no local POM # line 6, column 11 -> [Help 2]
The "java-project-parent" is one of the poms in the parent hierarchy.
What I've discovered is that running "mvn install" in the top-level aggregator pom isn't actually installing the artifacts in the submodules. When I looked in the local repo, the only thing in each directory in the local repo was a file like "...pom.lastUpdated". The actual POM wasn't there.
When I had the admin manually run "mvn install" in the first submodule, that actually installed the POM into the local repo. I have a feeling if he manually installs the other two parent poms, the build of the project that depends on all three of them will build fine.
I must be misunderstanding an important detail of how a build with submodules works. What am I missing?
run maven clean install with Force update option as below:
mvn clean install -U
Your hierarchy is probably broken. You can test that by building it in your local machine after wiping the local repository. Most likely you will find the same failures as on the build machine.
To fix it I would suggest remove all the relative path elements and adjust the structure so a build will work fine. Ideally you even break the pure parent projects out into separate projects and release them into your repository manager so that any other builds get them from there..
Try doing a mvn -U install to force a mvn trip to your nexus repo for updated aritfacts
Also run mvn with the -e switch to see detailed error messages

Resources