Maven: local dependency installed not found - maven

This is my project structure:
$ ls
pom.xml
README.md
rep-digital-api
rep-digital-common
So, rep-digital-api has rep-digital-common as dependency.
I first install succesfully rep-digital-common:
mvn -pl rep-digital-common clean package install
The problem appears when I'm trying to tun my rep-digital-api spring-boot service:
mvn clean package -pl rep-digital-api
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building rep-digital-api 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.417 s
[INFO] Finished at: 2018-08-13T15:35:28+02:00
[INFO] Final Memory: 28M/68M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project rep-digital-api: Could not resolve dependencies for project net.gencat.transversal.repositori.digital:rep-digital-api:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at net.gencat.transversal.repositori.digital:rep-digital-common:jar:0.0.1-SNAPSHOT: Failed to read artifact descriptor for net.gencat.transversal.repositori.digital:rep-digital-common:jar:0.0.1-SNAPSHOT: Could not find artifact net.gencat.transversal.repositori.digital:rep-digital:pom:0.0.1-SNAPSHOT -> [Help 1]
EDIT
Parent pom.xml fragment:
<modules>
<module>rep-digital-common</module>
<module>rep-digital-api</module>
</modules>
I've took a look on my local repositori. The package seems to be installed:
$ ls ~/.m2/repository/net/gencat/transversal/repositori/digital/rep-digital-common/
0.0.1-SNAPSHOT maven-metadata-local.xml
My ~/.m2/settings.xml fragment:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository/>
</settings>
EDIT 2
Parent pom.xml is:
<groupId>net.gencat.transversal.repositori.digital</groupId>
<artifactId>rep-digital</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
I've realized mvn is telling me that parent's pom.xml can't be resolved:
Could not find artifact net.gencat.transversal.repositori.digital:rep-digital:pom:0.0.1-SNAPSHOT

Related

Maven versions-maven-plugin NullPointerException when invoking with parent pom

I have a project folder structure where we use a parent pom and each subfolder contains its own pom.xml. Like this:
Project (pom.xml)
|- Addon-1 (pom.xml)
|- Addon-2 (pom.xml)
|- Addon-2 (pom_hotfix.xml)
Addon-1 and Addon-2 pom.xml contains a parent:
<parent>
<groupId>com.abc</groupId>
<artifactId>abc</artifactId>
<version>1.0.4</version>
<relativePath>../pom.xml</relativePath>
</parent>
In addition, the Addon-2 folder contains a second pom file, which doesn't have a parent. This is mandatory since the Hotfix is not allowed to contain the whole parent.
My pom_hotfix.xml looks like:
<project>
<modelVersion>4.0.0</modelVersion>
<artifactId>hotfix</artifactId>
<groupId>com.abc</groupId>
<name>hotfix</name>
<version>1.0.10</version>
<packaging>jar</packaging>
<build>
<resources>
<resource>
<directory>src/main/overlay/</directory>
<excludes>
<exclude></exclude>
</excludes>
</resource>
</resources>
</build>
</project>
The issue is now with the org.codehaus.mojo:versions-maven-plugin set command. If I invoke as follows:
mvn -B org.codehaus.mojo:versions-maven-plugin:2.7:set -DnewVersion=2.0.2 -f pom_hotfix.xml -X
I always receive the following error.
✔  mvn -B org.codehaus.mojo:versions-maven-plugin:2.7:set -DnewVersion=2.0.2 -f pom_hotfix.xml
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------< com.abc:hotfix >---------------
[INFO] Building hotfix 1.0.10
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- versions-maven-plugin:2.7:set (default-cli) # hotfix ---
[INFO] Searching for local aggregator root...
[INFO] Local aggregation root: /Users/abc/Project/
[INFO] Processing change of com.abc:hotfix:1.0.10 -> 2.0.2
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.264 s
[INFO] Finished at: 2020-07-13T11:27:41+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:versions-maven-plugin:2.7:set (default-cli) on project fixpack: Execution default-cli of goal org.codehaus.mojo:versions-maven-plugin:2.7:set failed. NullPointerException -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
If I temporarily remove the parent pom.xml in the Project folder, it's working fine. My goal is tho bump version inside of pom_hotfix.xml. I have no idea why I receive a null pointer.

mvn dependency:tree, multi-module and ${revision}

Does dependency:tree understand ${revision}?
I have a multi-module project X:
<groupId>org.X</groupId>
<artifactId>X-parent</artifactId>
<version>${revision}</version>
<properties>
<revision>8.0.0-SNAPSHOT</revision>
</properties>
<modules>
<module>X-A</module>
:
It is installed to my local .m2 (and only there).
I have a project Y which depends on X-A, revision 8.0.0-SNAPSHOT
Project Y's pom also includes:
<repositories>
<repository>
<id>rescarta</id>
<url>http://software.rescarta.org/nexus/content/groups/public/</url>
</repository>
</repositories>
When I run mvn dependency:tree on project Y, it complains:
$ mvn -U dependency:tree
[INFO] Scanning for projects...
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-dependency-plugin/3.0.1/maven-dependency-plugin-3.0.1.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-dependency-plugin/3.0.1/maven-dependency-plugin-3.0.1.pom (14 kB at 7.0 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-dependency-plugin/3.0.1/maven-dependency-plugin-3.0.1.jar
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-dependency-plugin/3.0.1/maven-dependency-plugin-3.0.1.jar (164 kB at 186 kB/s)
[INFO]
[INFO] -------------------< com.y:Y >-------------------
[INFO] Building Y 8.0.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
Downloading from rescarta: http://software.rescarta.org/nexus/content/groups/public/org/x/X-A/8.0.0-SNAPSHOT/maven-metadata.xml
Downloading from rescarta: http://software.rescarta.org/nexus/content/groups/public/org/x/X-parent/$%7Brevision%7D/X-parent-$%7Brevision%7D.pom
Downloading from central: https://repo.maven.apache.org/maven2/org/x/X-parent/$%7Brevision%7D/X-parent-$%7Brevision%7D.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.681 s
[INFO] Finished at: 2019-04-08T06:45:53+10:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project Y: Could not resolve dependencies for project com.y:Y:jar:8.0.0-SNAPSHOT: Failed to collect dependencies at org.x:X-A:jar:8.0.0-SNAPSHOT: Failed to read artifact descriptor for org.x:X-A:jar:8.0.0-SNAPSHOT: Could not find artifact org.x:X-parent:pom:${revision} in rescarta (http://software.rescarta.org/nexus/content/groups/public/) -> [Help 1]
Notice it is trying to download org.x:X-parent:pom:${revision}, not org.x:X-parent:pom:8.0.0-SNAPSHOT
Does dependency:tree not know how to resolve ${revision}?
The flatten-maven-plugin as explained at https://stackoverflow.com/a/52173650/1031689 seems to be an effective workaround.

Jenkins fails to parse POM with variables

tl;dr: mvn clean install works as expected, but Jenkins is not able to resolve variables in child poms.
We have a project with a main pom and multiple sub poms. It seems to fail in the sub pom with the variable ${project.version} not being resolved (see the error message below and scroll to its end).
Main pom:
<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>
<groupId>group</groupId>
<artifactId>artifact</artifactId>
<version>1.0.0.0-SNAPSHOT</version>
...
</project>
Sub pom:
<parent>
<groupId>group</groupId>
<artifactId>artifact</artifactId>
<version>${project.version}</version>
<relativePath>../pom.xml</relativePath>
</parent>
mvn clean install on the console works flawlessly:
[INFO] Installing /path/to/jenkins/workspace/Project/pom.xml to /path/to/.m2/repository/de/project/1.0.0.0-SNAPSHOT/project-1.0.0.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
...
[INFO] PROJECT 1.0.0.0-SNAPSHOT - EAR project ........... SUCCESS [ 5.038 s]
[INFO] PROJECT 1.0.0.0-SNAPSHOT - Aggregator project ........ SUCCESS [ 0.156 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:03 min
[INFO] Finished at: 2016-09-20T12:58:03+02:00
[INFO] Final Memory: 104M/1088M
[INFO] ------------------------------------------------------------------------
Jenkins fails to parse the pom and produces the following error:
Parsing POMs
ERROR: Failed to parse POMs
org.apache.maven.project.ProjectBuildingException: Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM: Failure to transfer my.package:project:pom:${project.version} from http://mynexus.com/content/groups/default was cached in the local repository, resolution will not be reattempted until the update interval of nexus-default has elapsed or updates are forced. Original error: Could not transfer artifact my.package:project:pom:${project.version} from/to nexus-default (http://mynexus.com/content/groups/default): Illegal character in path at index 78: http://mynexus.com/content/groups/default/my/package/project/${project.version}/panda-${project.version}.pom and 'parent.relativePath' points at wrong local POM # line 26, column 10
What has to be changed so that Jenkins can parse the pom file aswell?
The linked question states that maven would not be able to parse the child's properties as they wouldn't exist. The maven logs above show that this is not the case.
The information above is redacted. Typos are not the reason for this issue.
I fixed it by use Freestyle project Job instead of Maven project Job. Run native maven command in shell or locally didn't have this problem.
A similar error:
JENKINS-23846

Maven - Reactors (Aggregation)

I have a maven project with a following directory structure:
trunk
| pom.xml
| coreutils
| | pom.xml
| | src
| budgetCap
| | pom.xml
| | src
The content of trunk/pom.xml is :
<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
hxttp://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Ant2Maven</groupId>
<artifactId>parent</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<name>Parent Pom</name>
<modules>
<module>coreutils</module>
<module>budgetCap</module>
</modules>
In this structure, "budgetCap" is dependent on "coreutils",i.e. pom.xml of "budgetCap" contains a dependency of "coreutils"
Now I have two methods to build this project
First Method
Aggregation using Reactor
I will be inside trunk
So first of all I do mvn clean
shakim:trunk shakim.md$ mvn clean
Maven deletes the target folder of the two module in this order:
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] coreutils
[INFO] budgetCap Maven Webapp
[INFO] Parent Pom
Now when i do mvn install
shakim:trunk shakim.md$ mvn install
Maven starts building modules in the following order:
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] coreutils
[INFO] budgetCap Maven Webapp
[INFO] Parent Pom
In the given order, coreutils gets installed in the local repository successfully.
But budgetCap fails at the compilation giving an error that maven is unable to locate a class which was supposed to be produced by coreutils
the error message is as follows:
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building budgetCap Maven Webapp 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # budgetCap ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 4 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # budgetCap ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 65 source files to /Users/shakim.md/shakim/maven/ops/adq_services/trunk/budgetCap/target/classes
[INFO] -------------------------------------------------------------
[WARNING] COMPILATION WARNING :
[INFO] -------------------------------------------------------------
[WARNING]/Users/shakim.md/shakim/maven/ops/adq_services/trunk/budgetCap/src/main/java/com/adiquity/budgetCap/core/SingletonAggregator.java: /Users/shakim.md/shakim/maven/ops/adq_services/trunk/budgetCap/src/main/java/com/adiquity/budgetCap/core/SingletonAggregator.java uses unchecked or unsafe operations.
[WARNING]/Users/shakim.md/shakim/maven/ops/adq_services/trunk/budgetCap/src/main/java/com/adiquity/budgetCap/core/SingletonAggregator.java: Recompile with -Xlint:unchecked for details.
[INFO] 2 warnings
[INFO] -------------------------------------------------------------
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /Users/shakim.md/shakim/maven/ops/adq_services/trunk/budgetCap/src/main/java/com/adiquity/budgetCap/core/BudgetCapServer.java:[41,34] package com.adiquity.request.utils does not exist
[ERROR] /Users/shakim.md/shakim/maven/ops/adq_services/trunk/budgetCap/src/main/java/com/adiquity/budgetCap/utils/Utils.java:[9,34] package com.adiquity.request.utils does not exist
[ERROR] /Users/shakim.md/shakim/maven/ops/adq_services/trunk/budgetCap/src/main/java/com/adiquity/budgetCap/log/data/parser/ConversionParser.java:[16,34] package com.adiquity.request.utils does not exist
Briefly speaking this package package com.adiquity.request.utils is actually present in coreutils, which this module budgetCap must have located successfully, but it is not.
Second Method
Go inside coreutils and do a
shakim:coreutils shakim.md$ mvn clean install
Go inside budgetCap and do a
shakim:budgetCap shakim.md$ mvn clean install
budgetCap compiles successfully without reporting any kind of error.
My question is that I want to use Reactors in Maven and I am unable to figure out why the build fails on using 1st method whereas 2nd method of building completes smoothly??
I am not sure how to use reactors, do we need to include anything in pom of coreutils and budgetCap signifying that pom of trunk is the parent.
Note: I don't want to use inheritance in this project

maven can't find archetype in my repository

I'm trying to create my own maven archetype. For now, I'm going through this tutorial [here][1] without success. I'm able to build the archetype project okay, but when I try to generate a project from that archetype I get the error below. Maven can't seem to find the archetype I created. Can any one spot my problem? Is there some other recomended tutorial for createing a maven archetype? Thanks.
Maven version 3.0.3
Build Error:
AR3Y35-LAPTOP:EclipseWS Albert$ mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeGroupId=com.myarch.archetypes -DarchetypeArtifactId=component-archetype -DinteractiveMode=false
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:2.0:generate (default-cli) # standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:2.0:generate (default-cli) # standalone-pom <<<
[INFO]
[INFO] --- maven-archetype-plugin:2.0:generate (default-cli) # standalone-pom ---
[INFO] Generating project in Batch mode
[WARNING] Specified archetype not found.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.389s
[INFO] Finished at: Fri Sep 23 02:33:55 PDT 2011
[INFO] Final Memory: 7M/81M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.0:generate (default-cli) on project standalone-pom: The desired archetype does not exist (com.myarch.archetypes:component-archetype:1.0) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
AR3Y35-LAPTOP:EclipseWS Albert$
prototype pom.xml
<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>
<parent>
<groupId>com.myarch.templates</groupId>
<artifactId>component-template</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
<version>${version}</version>
<name>${group}</name>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
archetype.xml
<archetype xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype/1.0.0 http://maven.apache.org/xsd/archetype-1.0.0.xsd">
<id>component-archetype</id>
<sources>
<source>src/main/java/App.java</source>
</sources>
<testSources>
<source>src/test/java/AppTest.java</source>
</testSources>
<allowPartial>true</allowPartial>
</archetype>
For using a customized archetype, there has to be an entry made in the archetype-catalog.xml file which resides in the .m2/repository/archetype-catalog.xml in your home directory. For doing so, you need to install the archetype by using the following command:
mvn install archetype:update-local-catalog
After that, you will be able to use your new archetype while creating a new Maven project with the mvn archetype:generate command.
I needed to include -DarchetypeVersion={my.archetype.version} in the mvn archetpe:generate command
In my case the problem was that:
- update-local-catalog goal created file ~/.m2/repository/archetype-catalog.xml
- generate goal searches for file ~/.m2/archetype-catalog.xml
copying the file was a workaround. Not sure how I've fixed this. Sure now with maven 3.5.4 everything is ok.
It's telling you :
[WARNING] Specified archetype not found.
Did you install your archetype with
mvn install
before trying to use it ?
Executing the mvn install resolves the problem, after executing that from idea the problem got resolved.
From my own experience, You have to search for your groupId is accessible in the below link or not
http://repo.maven.apache.org/maven2/archetype-catalog.xml
I found out I had typo error then I've got error.

Resources