Maven not downloading dependency from custom repository - maven

I'm trying to share some code between two projects by loading it as a dependency via maven. For some reason, I can't get Maven to pick up the dependency.
Here's how I generated the shared JAR:
mvn install:install-file -Dfile=/Users/usr1/shared-code-1.0.0.jar -DpomFile=/Users/usr1/shared-code/pom.xml -DlocalRepositoryPath=.
This jar is held in a git repo github.com/myOrg/myRepo/repository where repository is the branch. The configuration described in the pom file for the shared code looks like this:
<groupId>com.myOrg</groupId>
<artifactId>shared-code</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
Here's how I defined the dependency and repository in my other code bases:
<dependency>
<groupId>com.myOrg</groupId>
<artifactId>shared-code</artifactId>
<version>1.0.0</version>
</dependency>
...
...
<repository>
<id>shared-code/id>
<name>Shared code for my stuff</name>
<url>http://raw.github.com/myOrg/myRepo/repository</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>\
The exact error I'm getting when I try and do a mvn clean package is:
[ERROR] Failed to execute goal on project otherCodeBase: Could not resolve dependencies for project otherCode:myProject:jar:latest: Failure to find com.myOrg:shared-code:jar:1.0.0 in http://[company's artifactory repo] was cached in the local repository, resolution will not be reattempted until the update interval of artifactory has elapsed or updates are forced -> [Help 1]
At first glance, it looks like Maven isn't even scanning the repository I defined in my other code's pom file, but when I execute mvn help:effective-pom it does appear. I should also add that I did make this repository public for the sake of getting it to work once. What gives?

Related

Adding a Github release to my maven pom.xml file

I need to add the following GitHub project as a dependency in my pom.xml:
https://github.com/loomchild/maligna
This project defines two maven modules: maligna and maligna-ui and I need both.
Unfortunately, it seems only the first module (maligna) is being deployed to a maven artifactory.
I tried using jitPack, as follows:
<pluginRepositories>
<pluginRepository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</pluginRepository>
</pluginRepositories>
...
<depencies>
...
<dependency>
<groupId>com.github.loomchild.maligna</groupId>
<artifactId>maligna-ui</artifactId>
<version>3.0.1</version>
</dependency>
...
</depencies>
but I get the following error
[ERROR] Failed to execute goal on project iutools-core: Could not resolve dependencies for project org.iutools:iutools-core:jar:1.0.2: Failure to find com.github.loomchild.maligna:maligna-ui:jar:3.0.1 in https://repository.apache.org/content/repositories/snapshots was cached in the local repository, resolution will not be reattempted until the update interval of snapshots has elapsed or updates are forced -> [Help 1]
Is there something I misundertand about how to use jitPack?

How to add maven dependency from github?

I'm trying to figure out how to configure my pom file to add a dependency that is published on Github but which does not appear in the central repository. The jpen library is published here:
https://github.com/qupath/qupath/tree/master/maven/repo/net/sourceforge/jpen/jpen/2-150301
Below is what I've added to my POM file:
<project>
...
<repositories>
<repository>
<id>msel.releases</id>
<url>https://github.com/qupath/qupath/tree/master/maven/repo/net/sourceforge/jpen/jpen/2-150301</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
</repository>
</repositories>
<dependencies>
...
<dependency>
<groupId>net.sourceforge.jpen</groupId>
<artifactId>jpen</artifactId>
<version>4.0.0</version>
</dependency>
</dependencies>
</project>
When I compile I get:
Failed to execute goal on project MacawSwing:
Could not resolve dependencies for project com.kitfox.macaw:MacawSwing:jar:1.0-SNAPSHOT:
Failed to collect dependencies for [com.kitfox.macaw:MacawCore:jar:1.0-SNAPSHOT (compile),
com.kitfox.docking:MacawDocking:jar:1.0-SNAPSHOT (compile),
net.sourceforge.jpen:jpen:jar:4.0.0 (compile),
javax.vecmath:vecmath:jar:1.5.2 (compile)]:
Failed to read artifact descriptor for com.kitfox.docking:MacawDocking:jar:1.0-SNAPSHOT:
Failure to find com.kitfox.macaw:Macaw:pom:1.0-SNAPSHOT in https://github.com/qupath/qupath/tree/master/maven/repo/net/sourceforge/jpen/jpen/2-150301
was cached in the local repository, resolution will not be reattempted until the update interval of msel.releases has elapsed or updates are forced -> [Help 1]
Those other dependencies are either local on my machine or in central and compiled fine before I tried to add the jpen dependency.
How can I fix this?
Some options:
If you are using a Nexus server you can add that dependency to that.
Add it to Maven Central (please contact the development team of the Git project).
Make use of JitPack. Clone the
project on GitHub and change the configuration to let it work with
JitPack. Also configure JitPack in your own Maven Pom.
It is also advisable to make use of released or tagged versions instead of a snapshot version.

Spring Asciidoctor Extensions not in correct repo?

Good afternoon guys,
I've been trying to get spring-asciidoctor-extensions to work with my documentation but for some reason maven can't find the dependency.
The error i got after my build attempt:
Failed to execute goal org.asciidoctor:asciidoctor-maven-plugin:1.5.5:process-asciidoc (generate-docs) on project organization: Execution generate-docs of goal org.asciidoctor:asciidoctor-maven-plugin:1.5.5:process-asciidoc failed: Plugin org.asciidoctor:asciidoctor-maven-plugin:1.5.5 or one of its dependencies could not be resolved: Failure to find io.spring.asciidoctor:spring-asciidoctor-extensions:jar:0.1.1.RELEASE 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 -> [Help 1]
I checked thier GitHub and looked around to find out that theres nothing in the maven repo (obvious from error) and in this question found that the repo is in https://repo.spring.io/release. Is there a way to reference a dependency to a repo directly? If not what can i do?
You can add the repo.spring.io repository to your pom.xml.
<repositories>
<repository>
<id>spring-repo</id>
<url>https://repo.spring.io/release</url>
</repository>
</repositories>
With that declaration in place you will be able to resolve this dependency:
<dependency>
<groupId>io.spring.asciidoctor</groupId>
<artifactId>spring-asciidoctor-extensions</artifactId>
<version>0.1.1.RELEASE</version>
</dependency>
More details in the docs.
Note: it is not possible to explicitly associate this dependency with that repository. Maven walks through the repositories in order of their declaration until a given dependency is resolved (or not) however if all of your other dependencies are resolved from Maven Central then the only dependency left to be resolved from repo.spring.io will be spring-asciidoctor-extensions.
I ran into this issue as well. My misconception at first was that I expected the dependencies to be resolved from the repositories section. However turns out that it's rather the pluginRepositories section. Like so:
<pluginRepositories>
<pluginRepository>
<id>spring-repo</id>
<url>https://repo.spring.io/release</url>
</pluginRepository>
</pluginRepositories>

Should I write repositories in my pom.xml?

I am new to Maven. If I start new project with Maven, should I know any repository URLs for it to work?
For example, this Hibernate tutorial http://docs.jboss.org/hibernate/core/3.3/reference/en/html/tutorial.html says about how to create a sample project with pom.xml text. But this pom.xml does not contain any repositories.
So, my m2eclipse plugin says, for example Project build error: 'dependencies.dependency.version' for org.hibernate:hibernate-core:jar is missing., for all dependency tag in pom.xml
Is this because of repositories absence?
Where to know repositories URLs? Is there one big repository? Why doesn't it included by default?
UPDATE 1
It is said here, that Maven should use "central" repository by default: http://maven.apache.org/guides/introduction/introduction-to-repositories.html
I have searched there for hibernate-code artifact and found it. So, this artifact IS in central repository. By my maven says dependency not found. Hence it doesn't use it's central repository. Why?
Apparently your Hibernate dependency is missing <version> tag:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.6.9.Final</version> <!-- this line is missing -->
</dependency>
Note that you don't have to specify version of dependencies previously declared in <dependencyManagement>.
Old answer:
Every build script (not only with Maven) should be reproducible and independent from environment. Standard pom.xml (called super pom), which every pom.xml inherits from, already defines main Maven central repository:
<repositories>
<repository>
<id>central</id>
<name>Maven Repository Switchboard</name>
<layout>default</layout>
<url>https://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
You don't have to define this repository, and you don't have to define any others if all your dependencies are there. On the other hand if you are using some external repositories, you must add them to pom.xml, so that every developer is always able to build.
The bottom line is: if you can build the project having a completely empty repository, your pom.xml is fine.
It's not advisable to define repositories in POM files as that causes a lot of issues (Maven will search those repositories for ANY artifact even the ones available at Central, poor portability, ...)
Best approach: Setup a repository manager (Artifactory, Nexus) and edit your settings.xml file to use the repo manager as a mirror.
Second best approach: Define the required repositories in your settings.xml file, not in your pom.xml files.
Repositories in poms is a bad idea.

How can i use SVN as Maven Repository

I am working on project which has multiple dependencies. Most of the dependencies are available at our centralized maven repository. My project includes some JARs which only specific to my application and unavailable at our Maven repo. Due to some policy/restriction i cant deploy that jars to our maven repository.
When i install these jars in my local repository(i.e.UserHome/.m2/repository) and compile the code its working fine.
Now i want these dependencies in SVN so that we can build the application package using Continuum.(We cant refer local dependency from Continuum server.)
Just to achieve these i copied the locally installed dependency from .m2/repository and committed it in SVN. Then i declared repository in pom.xml like..
<repositories>
<repository>
<id>repo.pu</id>
<name>repo.pu</name>
<url>https://URL/migration2/APP1/src/main/lib/</url>
<layout>default</layout>
</repository>
</repositories>
Now to use dependency from above repo i added code like...
<dependencies>
<dependency>
<groupId>repo.pu</groupId>
<artifactId>Ptestval</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
When i type mvn verify i am getting the below error..
[ERROR] Failed to execute goal on project APP1: Could not resolve dependencies f
or project fileservices.migration2:APP1:jar:1.0: Failed to collect dependencies
for [repo.pu:Ptestval:jar:1.0 (compile)]: Failed to read artifact descriptor for
repo.pu:Ptestval:jar:1.0: Could not transfer artifact repo.pu:Ptestval:pom:1.0
from/to repo.pu (https://URL/migration2/APP1/src/main/lib/): Access denied to:
https://URL/migration2/APP1/src/main/lib/repo/pu/Ptestv
al/1.0/Ptestval-1.0.pom -> [Help 1]
Could you please someone help me to resolve these issue?
EDIT: I created a repository like ..
<repositories>
<repository>
<id>repo.pu</id>
<name>repo.pu</name>
<url>https://SVNUserName:SVNPassword#SVN_URL/BaseProj/ProjA/src/main/lib</url>
<layout>default</layout>
</repository>
</repositories>
This technique works perfectly at my Personal laptop. Maven downloads the listed dependency from repo.
But when tries to use the same in my project on company network it is not working .. It gives the same error which i was getting before using this approach.
Can anyone help me please? What would be problem? Is it a network issue?
Set up a repository manager like Nexus and don't abuse Subversion for something it was not designed for. This is unfortunately done in Google Code.
You must configure your project to use wagon-scm.
See http://maven.apache.org/wagon/wagon-providers/wagon-scm/usage.html

Resources