Maven is picking up the oldest snapshot in Archiva - why? - maven

I have a projectA-parent with the following structure:
projectA-parent|
----------------|projectA
----------------|projectA-core
----------------|projectA-api
The module projectA simply defines dependencies to core and api [1], so I can just define a dependency to projectA in other projects that need both the core and the api. I deploy the project to Archiva (1.4-M2), to a SNAPSHOT repository.
I have another project X where I define a dependency to projectA, and this afternoon the goal "mvn compile" started failing with unresolved compilation issues. Upon investigation with "mvn dependency:tree" on that project I discovered that, under projectA, the dependency to projectA-core was declared as "runtime". While this morning it was like this, I performed several mvn installs since where the scope is "compile" (see [1], where the most recent pom definition is listed).
Looking at archiva, I see the following files for this project (abbreviated):
projectA-0.0.7-20120712.084920-61-tests.jar
projectA-0.0.7-20120712.084920-61-tests.jar.md5
projectA-0.0.7-20120712.084920-61-tests.jar.sha1
projectA-0.0.7-20120712.084920-61.jar
projectA-0.0.7-20120712.084920-61.jar.md5
projectA-0.0.7-20120712.084920-61.jar.sha1
projectA-0.0.7-20120712.084920-61.pom
projectA-0.0.7-20120712.084920-61.pom.md5
projectA-0.0.7-20120712.084920-61.pom.sha1
projectA-0.0.7-20120712.172412-87-tests.jar
projectA-0.0.7-20120712.172412-87-tests.jar.md5
projectA-0.0.7-20120712.172412-87-tests.jar.sha1
projectA-0.0.7-20120712.172412-87.pom
projectA-0.0.7-20120712.172412-87.pom.md5
projectA-0.0.7-20120712.172412-87.pom.sha1
projectA-0.0.7-20120712.180733-90.pom
projectA-0.0.7-20120712.180733-90.pom.md5
projectA-0.0.7-20120712.180733-90.pom.sha1
Here's the interesting part: if I delete projectA from my local .m2/repository, even if I "mvn compile -U" I will get th 08:49 version, not the 18:07 one! This means either maven or archiva are resolving the 1st sNAPSHOT of the day and not the most recent one.
Why is that, and how can one solve this?
[1]:
<dependencies>
<dependency>
<groupId>com.projectA</groupId>
<artifactId>projectA-api</artifactId>
<version>${project.version}</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.projectA</groupId>
<artifactId>projectA-core</artifactId>
<version>${project.version}</version>
<type>jar</type>
<scope>runtime</scope>
</dependency>
</dependencies>

What is the packaging of your projectA ('jar' or 'pom'). It only exists a 'jar' artefact for 08:49.
I suppose you changed the packaging to 'pom'. Thus if you declare the library as dependency in other projects you have to set <type>pom</type>.

Related

How to figure out in what pom a dependency from effective pom is defined in IntelliJ Idea?

I have a big project that has parent pom, this one has another parent; in the project's pom file another project with bom file is included as a dependency, etc.
I click on pom and generate effective pom. Inside I see a dependency, for example this one
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.10</version>
</dependency>
Is there an easy way in IntelliJ to find the pom where this dependency is defined?
In Ultimate version it's possible to generate a diagram for all maven dependencies:
https://www.jetbrains.com/help/idea/work-with-maven-dependencies.html#maven_dependency_diagram
Or you can execute mvn dependency:tree to build full dependency tree.
https://maven.apache.org/plugins/maven-dependency-plugin/examples/resolving-conflicts-using-the-dependency-tree.html
https://www.mkyong.com/maven/maven-display-project-dependency/

Transitive Dependency How do i exclude. -- Maven

I have the below project structure under lib for project 2.
Project 2 (under lib)
- Maven dependencies (JARs)
- project 1 JAR (it has JARs in lib)
- Maven dependencies of project 1 (JARs)
I want to exclude all JARs under project 1 while preparing project 2.
I'm currently using the below in my POMs (both project 1 and project 2)
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
When building project 1, I want it to build as an executable JAR with lib.
However when building project 2, I want project 1 as only a compiled JAR (meaning with only class files and not having lib (JARs)).
Project 1 is included as a normal dependency in Project 2. Can anyone help me out?
If you want to exclude all dependencies of a given dependencies, use exclusions
https://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html
and do it like
<dependency>
<groupId>sample.ProjectA</groupId>
<artifactId>Project-A</artifactId>
<version>1.0</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
Of course, you have to be sure that the missing transitive dependencies are not needed at runtime.
If I understand correctly project 1 builds a jar which has inside a lib directory with the dependencies.
You could in project 1 have 2 assembly executions, one the basic jar and another with dependencies and execute manifest, normally you use a different "classifier" for multiple artifacts of the same project.
Otherwise you would need to "repackage" the jars to remove the libs you don't want using some plugin like Shade.
I think the first option is much better, also by default if you publish it to a repository both jars will be published so other people can get one or the other.

Excluding transitive dependency not working

Project A references Project B. Project B has included a local dependency. This local dependency unfortunately has a dependency to net.java.dev.designgridlayout in version 1.5.
We want to use net.java.dev.designgridlayout in version 1.11 in Project A but we are not able to "overwrite" the dependency. Eclipse always uses the dependency from Project B.
We already tried to exclude the 1.5 version from the local dependency, but it doesn't work.
The strange thing is, that Eclipse successfully resolves a class that has been added with version 1.11. For an already existing class, however, eclipse resolves it from the transitive dependency from de.someCompany.
Project B:
<dependencies>
<dependency>
<groupId>de.someCompany</groupId>
<artifactId>fs-client</artifactId>
<version>5.1.209</version>
<exclusions>
<exclusion>
<groupId>net.java.dev.designgridlayout</groupId>
<artifactId>designgridlayout</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.java.dev.designgridlayout</groupId>
<artifactId>designgridlayout</artifactId>
<version>1.11</version>
</dependency>
</dependencies>
Project A:
<dependencies>
<dependency>
<groupId>Project-B</groupId>
<artifactId>Project-B</artifactId>
<version>1503.01</version>
</dependency>
</dependencies>
I also tried to include the 1.11 dependency in Project A.
We even tried to install the DesignGridLayout V. 1.11 in the local dependency and to change the groupID and artifactId to something different, but it cannot even be found by Eclipse for some reason. If it would be possible to include the DesignGridLayout with another groupId and artifactId, I think it would work.
mvn install:install-file -Dfile=lib\designgridlayout.jar -DgroupId=com.company.designgridlayout -DartifactId=design-grid-layout -Dversion=1.11 -DgeneratePom=true -Dpackaging=jar -DlocalRepositoryPath="%USERPROFILE%\.m2\repository"
Not sure - but:
Your project A has a dependency to itself? Shouldn't it use project-b?
Its not a good idea to change group or artifact id's as maven can no longer detect its the same artifact. If you do a custom version the version number should be enough.
If you add the dependency in your own pom then you don't need to exclude the artifact, since the groupId and artifactId are the same. The version in your own pom will win in project-b. If project a defines that dependency again itself that version will win.
I would do a mvn dependency:tree on project-a pom to see where the dependencies come from.
For eclipse: it indexes the local repository. In the maven settings there is a re-index button. So if you manually copy jars in there that may help eclipse to find the artifact. But that workaround would need to be done on every machine. I would not count that as solution. In the maven world artifact-resolution is an infrastructure issue and should not be handled per project. The way this is done should be transparent through the settings.xml

how to add my one project jar in another maven project in netbeans

I have one project jar oauth.
I want to add it in another maven project . I tried to change pom.xml file but no effect. Can anyone please suggest me?
I tried to add following dependency in my pom.xml file:
<dependency>
<groupId>com.payupaisa.oauth</groupId>
<artifactId>auth</artifactId>
<version>1.0.0</version>
<type>jar</type>
<scope>system</scope>
<systemPath>${basedir}/src/main/webapps/WEB-INF/lib/auth.jar</systemPath>
</dependency>
With the assumption that you have that auth.jar in your local repository (as it builds fine).
Why don't you give a try like this.
<dependency>
<groupId>com.payupaisa.oauth</groupId>
<artifactId>auth</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
Honestly speaking I don't prefer to give the jar location in my pom file and using scope as system, I leave this task to handle by Maven to resolve all the artifacts either by searching in local maven repository first(/.m2) or in MAVEN CENTRAL REPO if it is a 3rd party jar.

Need explanation for maven error please

http://blog.bigpixel.ro/2012/07/building-cc-applications-with-maven/comment-page-1/#comment-8196
I'm following the example above for the maven nar plugin, but I get the following error when I do a mvn package
“could not find artifact net.sf.antcontrib:cpptasks-parallel:jar:1.0-beta-5-parallel-1-SNAPSHOT” but I see the following folder tree and its contents in my ~/.m2/repository... What gives?
~
.m2
repository
net
sf
antcontrib
cpptasks-parallel
1.0-beta-5-parallel-1-SNAPSHOT
Change dependency
<dependency>
<groupId>net.sf.antcontrib</groupId>
<artifactId>cpptasks-parallel</artifactId>
<version>1.0-beta-5-parallel-1-SNAPSHOT</version>
</dependency>
to
<dependency>
<groupId>org.codeswarm</groupId>
<artifactId>cpptasks-parallel</artifactId>
<version>20121119</version>
</dependency>
Unfortunately, neither maven-nar-plugin nor cpptasks-parallel are currently deployed to Central. So you need to mvn install them yourself (or better, mvn deploy them to your own Maven repository). You can find both projects on GitHub.
EDIT: nar-maven-plugin version 3.0.0 has been released, and is now available from Maven Central. Two notes:
The groupId and artifactId changed; the GAV is now:
<plugin>
<groupId>com.github.maven-nar</groupId>
<artifactId>nar-maven-plugin</artifactId>
<version>3.0.0</version>
</plugin>
The cpptasks-parallel project has been merged into nar-maven-plugin, so no need to worry about that dependency anymore.

Resources