Dependency resolution configuration in Artifactory - maven

Recently we started to work with Artifactory. We configured settings.xml as Artifactory proposed. However we have problems downloading jars while running "mvn compile", even if they appear in Artifactory repo. Adding explicitly repo1-cache solves the compilation problem but download is performed from remote repository rather than from Artifactory.
<repository>
<id>My Repository</id>
<name>MyRepository-releases</name>
<url>http://mvn-srv:8081/artifactory/repo1</url>
</repository>
What should be added to settings.xml in for resolving automatically dependencies and fetching them from artifactory rather than accessing remote servers each time?
settings.xml:
<?xml version="1.0" encoding="UTF-8"?>
<settings
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"
xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<profiles>
<profile>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>libs-release</name>
<url>http://mvn-srv:8081/artifactory/libs-release</url>
</repository>
<repository>
<snapshots>
<enabled>true</enabled>
</snapshots>
<id>snapshots</id>
<name>libs-snapshot</name>
<url>http://mvn-srv:8081/artifactory/libs-snapshot</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>plugins-release</name>
<url>http://mvn-srv:8081/artifactory/plugins-release</url>
</pluginRepository>
<pluginRepository>
<snapshots />
<id>snapshots</id>
<name>plugins-snapshot</name>
<url>http://mvn-srv:8081/artifactory/plugins-snapshot</url>
</pluginRepository>
</pluginRepositories>
<id>artifactory</id>
</profile>
</profiles>
<activeProfiles>
<activeProfile>artifactory</activeProfile>
</activeProfiles>
<servers>
<server>
<id>MyRepository</id>
</server>
</servers>
Compilation error:
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 14.355s
[INFO] Finished at: Wed Nov 14 14:52:31 IST 2012
[INFO] Final Memory: 4M/15M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project common: Could not resolve dependencies for project com.myc
ompany.app:common:jar:1.0-SNAPSHOT: The following artifacts could not be resolved: commons-jxpath:co
mmons-jxpath:jar:1.3-osgi, xpp3:xpp3_min:jar:1.1.3.4.O-osgi, net.java.dev.stax-utils:stax-utils:jar:
20080702-osgi, net.sf.saxon:saxon:jar:8.9.0.4-osgi, net.sf.saxon:saxon-dom:jar:8.9.0.4-osgi, net.sf.
saxon:saxon-xqj:jar:8.9.0.4, dom4j:dom4j:jar:1.6.1-osgi, mx4j:mx4j-jmx:jar:2.1.1-osgi, mx4j:mx4j-imp
l:jar:2.1.1-osgi, mx4j:mx4j-tools:jar:2.1.1-osgi, mx4j:mx4j-remote:jar:2.1.1-osgi, com.yourkit:yjp-c
ontroller-api-redist:jar:9.0.8, org.apache.geronimo.specs:geronimo-jms_1.1_spec:jar:1.1-osgi, common
s-codec:commons-codec:jar:1.3-osgi, commons-httpclient:commons-httpclient:jar:3.1-osgi, quartz:quart
z-all:jar:1.6.6: Could not find artifact commons-jxpath:commons-jxpath:jar:1.3-osgi in central (http
://mvn-srv:8081/artifactory/libs-release) -> [Help 1]

Adding to #duncan-jones excellent answer, great way to troubleshoot resolution is performing Trace Artifact Retrieval call, in your case:
http://mvn-srv:8081/artifactory/libs-release/commons-jxpath/commons-jxpath/1.3-osgi/commons-jxpath-1.3-osgi.jar?trace
BTW, I don't even see the 1.3-osgi version in repo1.

You need to ensure your virtual repositories map to the real repositories you expect.
For example, libs-release will typically map to both internal and external release repositories. Perhaps this is mis-configured, resulting in it not hitting the repositories you want.
In Artifactory, go to the Admin page and look at Configuration > Repositories. At the bottom of the page, take a look at your virtual repositories. Double-clicking on them will show you what is included.
For me, libs-release includes libs-release-local, ext-release-local and remote-repos. The latter is another virtual repository that maps to all the external repositories listed in my installation, e.g. codehaus, repo1, jboss, google-code, ...
Perhaps one of these virtual repositories is missing repo1?

Related

Mule XML SDK and its Error in Maven Settings.xml

I'm doing the XML SDK in Mule 4.2.2 with Maven 3.6.3 [though Mule inbuild using (3.6.9)] and AnypointStudio 7.4.2 . Please clarify my doubts
1) Is that XML SDK connectorPlugin creation is supported only in Mule-EE version or public?
2) I'm using the below Maven command and settings.xml , which is throwing 401 Unauthorized (Warning) and error as 'Archetype' issue.
mvn archetype:generate -DarchetypeGroupId=org.mule.extensions -DarchetypeArtifactId=xml-mule-extensions-archetype -DarchetypeVersion=1.0.1 -DgroupId=org.mule.extension -DartifactId=error-handler-framework -DmuleConnectorName=ErrorHandler
Error I'm getting as below. But i can able to assess this URL https://repository.mulesoft.org/releases/ without Login. Not sure why its throwing 401
[WARNING] Failure to transfer org.mule.tools/maven-metadata.xml from
https://repository.mulesoft.org/releases/ was cached in the local repository, resolution will not be reattempted until the update interval of mulesoft-releases has elapsed or updates are forced. Original error: Could not transfer metadata org.mule.tools/maven-metadata.xml from/to mulesoft-releases (https://repository.mulesoft.org/releases/): authenticationrequired (401)
[ERROR] No plugin found for prefix 'archetype' in the current project and in the plugin groups [org.mule.tools, org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (C:\Users\jxsubr\.m2\repository), mulesoft-releases (https://repository.mulesoft.org/releases/), central (https://repo.maven.apache.org/maven2)]
Below is the settings.xml
<?xml version="1.0"?>
<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
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>C:\Users\star\.m2\repository</localRepository>
<profiles>
<profile>
<id>Mule</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>mulesoft-releases</id>
<name>MuleSoft Repository</name>
<url>http://repository.mulesoft.org/releases/</url>
<layout>default</layout>
</repository>
</repositories>
</profile>
<profile>
<id>standard-repositories</id>
<repositories>
<repository>
<id>Central</id>
<name>Central</name>
<url>http://repo1.maven.org/maven2/</url>
<layout>default</layout>
</repository>
<repository>
<id>mulesoft-releases</id>
<name>MuleSoft Releases Repository</name>
<url>http://repository.mulesoft.org/releases/</url>
<layout>default</layout>
</repository>
<repository>
<id>mulesoft-ee-release</id>
<url>https://repository.mulesoft.org/nexus-ee/content/repositories/releases-ee/</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
..............
</profile>
I also tried giving Public Repo, instead Mule-ee in the above settings. Still the same error. Please direct me a standard settings.xml for Mule if any.
3) Though Mule inbuild for this runtime 4.2.2 using Maven 3.6.9. Can we use lower version 3.6.3 (I believe this is the stable version now)?
Reference: https://docs.mulesoft.com/mule-sdk/1.1/xml-sdk
Thanks in advance for your help. Please let me know if needed more information.
I think you need to declare the repos as pluginRepositories too for the archetype to work. HTH
This dependency is available only for MuleSoft Enterprise Maven customer repository only.
IN XML SDK other than transform message this ee xsd may not require., I have created a log forwarder without using this dependency.
Log Forwarding Connector Mule XML-SDK - DZone
https://dzone.com/articles/mule-log-forwarder-connector-xml-sdk
https://docs.mulesoft.com/mule-runtime/3.6/configuring-maven-to-work-with-mule-esb#%C2%A0referencing-mulesoft-s-enterprise-repositories.

Maven could not resolve dependency of WebSphere provided dependency

I am trying to import a legacy application on IntelliJ and most of the modules have dependencies to com.ibm.tools.target.was and com.ibm.tools.target.portal artifacts.
I am getting this in the Maven window of IntelliJ:
This is the error message I am getting on mvn install:
Failed to execute goal on project xxx-managers: Could not resolve dependencies for project com.xxx.xxx.xxx-managers:xxx-managers:ejb:0.0.1-SNAPSHOT: Failure to find com.ibm.tools.target:was:pom:8.0.0 in 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
I tried to imitate a similar procedure found in the IBM web knowledge center (https://www.ibm.com/support/knowledgecenter/en/SSHR6W/com.ibm.websphere.wdt.doc/topics/install_server_apis.html) but it did not work.
I added the was_public.pom as maven project and imported the project as a dependency to my other module.
I also tried to add WebSphere as a library dependency:
Nothing worked.
Please help, thanks in advance.
EDIT: This is my settings.xml (I copied it from an other environment in which the application is working) and it includes IBM repositories:
<?xml version="1.0" encoding="UTF-8"?>
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<profiles>
<profile>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
<id>ibm-maven-repo</id>
<name>ibm-maven-repo</name>
<url>http://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/wasdev/maven/repository/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
<id>ibm-maven-repo</id>
<name>ibm-maven-repo</name>
<url>http://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/wasdev/maven/repository/</url>
</pluginRepository>
</pluginRepositories>
<id>standard-extra-repos</id>
</profile>
</profiles>
<activeProfiles>
<activeProfile>standard-extra-repos</activeProfile>
</activeProfiles>
</settings>
You miss some artifacts, e.g. com.ibm.tools.target:was:pom:8.0.0, and you need to either specify a repository in your settings.xml, where it should come from or install these artifacts into your local repository.

Order of maven repositories in settings.xml

I have a settings.xml which looks like below:-
<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 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>nReleases</id>
<username>test</username>
<password>test123</password>
</server>
<server>
<id>nSnapshots</id>
<username>test</username>
<password>test123</password>
</server>
</servers>
<profiles>
<profile>
<id>space</id>
<repositories>
<repository>
<id>central</id>
<url>http://repo1.maven.org/maven2</url>
</repository>
<repository>
<id>nReleases</id>
<name>Releases</name>
<url>http://someserver/repository/maven-releases/</url>
</repository>
<repository>
<id>nSnapshots</id>
<name>Snapshots</name>
<url>http://someserver/repository/maven-snapshots/</url>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>space</activeProfile>
</activeProfiles>
</settings>
I want maven to check repo1.maven.org first and then only look in someserver. Can someone let me know how this can be achieved?
I am using Maven 3.3.9.
I have gone through this question and tried to change the order in which repos are declared in profile but it did not help.
<profile>
<id>space</id>
<repositories>
<repository>
<id>nReleases</id>
<name>Releases</name>
<url>http://someserver/repository/maven-releases/</url>
</repository>
<repository>
<id>nSnapshots</id>
<name>Snapshots</name>
<url>http://someserver/repository/maven-snapshots/</url>
</repository>
<repository>
<id>central</id>
<url>http://repo1.maven.org/maven2</url>
</repository>
</repositories>
</profile>
Logs while doing mvn clean install
tuk-MacBook-Pro-4:camel tuk$ mvn clean install
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building camel 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
Downloading: http://someserver/repository/maven-releases/org/apache/camel/camel-redis/2.16.3/camel-redis-2.16.3.pom
Downloading: http://someserver/repository/maven-snapshots/org/apache/camel/camel-redis/2.16.3/camel-redis-2.16.3.pom
The order of the repository inside the settings was not clearly specified in Maven 2, but starting with Maven 3 (and the fix of of MNG-4400), the repositories are always tried in their declaration order in the settings.
What can happen, and what is likely the cause of your problem, is that Maven tries a repository, fails in doing so, and stores in your local repository the fact that it tried and failed. This results in the creation of .lastUpdated files in your local repository, storing this information. The consequence is that Maven will not re-try to download the dependency from a repository where it knows the download failed in the past. Thus, when you start a command and the project requires an artifact not present in your local repository, Maven will still try the repositories in their order of declaration, but it will skip the ones it knows already failed.
But you can force it to bypass this mechanism by passing the -U flag on the command line. It forces Maven to update the releases and snapshots dependencies, without looking into .lastUpdated files. This way, it will re-try every active remote repositories.

Maven ignores a repository

I'm unable to get Maven download an artifact
<dependency>
<groupId>org.jboss.test-jsf</groupId>
<artifactId>jsf-mock</artifactId>
<version>1.1.9</version>
<scope>test</scope>
</dependency>
This dependency isn't in the Maven Central. I've added the proper repository to my settings.
<profiles>
<profile>
<id>barbucha</id>
</profile>
<repositories>
<repository>
<id>jboss</id>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
<url>http://repository.jboss.org/nexus/content/groups/public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>jboss-plug</id>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
<url>http://repository.jboss.org/nexus/content/groups/public/</url>
</pluginRepository>
</pluginRepositories>
</profiles>
Then I build things using the barbucha profile. However maven doesn't use the JBoss repository at all. It tries to get the missing dependency from Central instead. It tries to download the dependency twice and then fails:
[INFO] Downloading: http://repo.maven.apache.org/maven2/org/jboss/test-jsf/jsf-mock/1.1.9/jsf-mock-1.1.9.pom
[WARNING] The POM for org.jboss.test-jsf:jsf-mock:jar:1.1.9 is missing, no dependency information available
[INFO] Downloading: http://repo.maven.apache.org/maven2/org/jboss/test-jsf/jsf-mock/1.1.9/jsf-mock-1.1.9.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project: Could not resolve dependencies for project: Could not find artifact org.jboss.test-jsf:jsf-mock:jar:1.1.9 in central (http://repo.maven.apache.org/maven2) -> [Help 1]
The behavior is very strange and sadly critical to me. I googled a long time, but nothing found, what can cause the problem. The only reason can be the profile if not activated. But that isn't my case.
Oh, it was so simple - my settings are just malformed:
<profiles>
<profile>
<id>barbucha</id>
</profile> <<< this must be at the end (at <!-- #1 --->)
<repositories>
... <!-- this part must be inside of profile -->
</pluginRepositories>
<!-- #1 --->
</profiles>
I apologize. (Hopefully it may help to someone.)

Why is Maven downloading from the wrong repository?

I'm a newbie to Maven. I'm trying to setup a local Archiva 1.3.6 server to act as a repository server for a project's internal artifact, as well as mirror to external repos. Things work fine except for snapshots. I'm using Maven version 3.0.5.
Here are the mirror settings in my settings.xml file
<mirrors>
<mirror>
<id>internal</id>
<mirrorOf>external:*</mirrorOf>
<name>My Maven Repository</name>
<url>http://my.repo.server:9000/archiva/repository/internal/</url>
</mirror>
</mirrors>
During the build, Maven tries to download the snapshot artifact from the wrong repository. I have 2 repositories set in the parent's parent pom.xml: internal and snapshots.
<repositories>
<repository>
<id>internal</id>
<url>http://my.repo.server:9000/archiva/repository/internal/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>snapshots</id>
<url>http://my.repo.server:9000/archiva/repository/snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
In the project's pom.xml I have the following dependency:
<dependency>
<groupId>com.mygroup</groupId>
<artifactId>metadata-framework</artifactId>
<version>1.0.3.SNAPSHOT</version>
</dependency>
During the build Maven tries to do this:
Downloading:
.../archiva/repository/**snapshots**/com/mygroup/metadata-framework/1.0.3.SNAPSHOT/maven-metadata.xml
Downloaded:
.../archiva/repository/**snapshots**/com/mygroup/metadata-framework/1.0.3.SNAPSHOT/maven-metadata.xml (795 B at 16.9 KB/sec)
Downloading:
.../archiva/repository/**internal**/com/mygroup/metadata-framework/1.0.3.20130908.081541-1/cems-metadata-framework-1.0.3.20130908.081541-1.pom
[WARNING] The POM for com.myground:metadata-framework:jar:1.0.3.20130908.081541-1 is missing, no dependen
cy information available
I verified the files in snapshot repo is correct, that it has properly generated maven-metadata.xml and etc. it appears that Maven downloaded the metadata correctly from snapshot repo, determined the right timestamped version, but somehow it decided to download the actual file from internal repo instead of snapshots, which lead to 404 and failed build.
I have no idea how Maven works, please help.
#lee - Here's how I download custom artifacts from an internal snapshots repo within Archiva. I use this config every day.
settingsl.xml:
Let's say I have a virtual repo named "help".
help is comprised of outside-facing repos and 2 internal-facing repos. Those 2 internal-facing repos are:
help-internal
help-snapshots
Under the <mirrors> section, I declare:
<mirror>
<id>help</id>
<mirrorOf>*, !help-snapshots</mirrorOf>
<name>The Help Repository</name>
<url>http://blah:8080/archiva/repository/help/</url>
</mirror>
Under the <servers> section, I declare:
<server>
<id>help</id>
<username>my_user_name</username>
<password>{my_encrypted_pwd}</password>
</server>
<server>
<id>help-snapshots</id>
<username>my_user_name</username>
<password>{my_encrypted_pwd}</password>
</server>
And now the final bit. In my projects' pom's that use in-house snapshots, I include this:
<repositories>
<repository>
<id>help-snapshots</id>
<url>http://blah:8080/archiva/repository/help-snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
More concisely, and without modifying any pom.xml, you could define an all repository group in archiva which contains both internal and snapshots, and then add the following in your .m2/settings.xml:
<mirrors>
<mirror><id>myGroup</id><mirrorOf>*</mirrorOf>
<url>http://my.repo.server:9000/archiva/repository/all/</url>
</mirror>
</mirrors>
<profiles>
<profile><id>alwaysactive</id>
<activation><activeByDefault>true</activeByDefault></activation>
<repositories>
<repository><id>unused</id><url>unused</url></repository>
</repositories>
</profile>
<profiles>
I know this post is old by in order for maven to search in a snapshot repository the version should end with "-SNAPSHOT" (rather than ".SNAPSHOT")

Resources