How can we define a repository in the pom.xml?
For example if dependency is not found in the repository defined in settings.xml then search for the dependency in the repository defined in pom.xml.
An example on how this can be achieved would be great.
I am aware that placing repositories in the pom.xml is not a good option, but circumstances are pushing for this.
<repositories>
<repository>
<id>java.net</id>
<url>https://maven.java.net/content/repositories/public/</url>
</repository>
</repositories>
From the documentation (example reproduced as is here):
<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/xsd/maven-4.0.0.xsd">
...
<repositories>
<repository>
<releases>
<enabled>false</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
<id>codehausSnapshots</id>
<name>Codehaus Snapshots</name>
<url>http://snapshots.maven.codehaus.org/maven2</url>
<layout>default</layout>
</repository>
</repositories>
<pluginRepositories>
...
</pluginRepositories>
...
</project>
Related
I am creating parent-pom. There we are defining build->plugin->dependencies.
It can fetch dependencies from maven but it couldn't fetch dependencies from our internal Maven repository. getting below error
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-antrun-plugin:1.2:check (validate) on
project parent-pom: Execution validate of goal
org.apache.maven.plugins:maven-antrun-plugin:1.2:check failed: Plugin
org.apache.maven.plugins:maven-antrun-plugin:1.2 or one of its
dependencies could not be resolved: Could not find artifact
org.tools:build-tool:jar:1.0 in central
(https://repo.maven.apache.org/maven2) -> [Help 1]
It is trying to pull dependency from https://repo.maven.apache.org/maven2 instead of our internal Maven repository. I have configured repositories and dependencyManagement still it is trying to fetch from https://repo.maven.apache.org/maven2 instead of going to our internal repositories.
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.global</groupId>
<artifactId>parent-pom</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<repositories>
<repository>
<id>archiva.global</id>
<name>Internal Release Repository</name>
<url>https://archiva.global.com/repository/internal</url>
</repository>
<repository>
<id>archiva.snapshots</id>
<name>Internal Snapshots Repository</name>
<url>https://archiva.global.com/repository/snapshots</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>archiva.internal</id>
<name>Internal Release Repository</name>
<url>https://archiva.global.com/repository/internal</url>
</repository>
<snapshotRepository>
<id>archiva.snapshots</id>
<name>Internal Snapshots Repository</name>
<url>https://archiva.global.com/repository/snapshots</url>
</snapshotRepository>
</distributionManagement>
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.2</version>
...
<dependencies>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
<version>1.7.1</version>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-launcher</artifactId>
<version>1.7.1</version>
</dependency>
<dependency>
<groupId>org.tools</groupId>
<artifactId>build-tool</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
...
</project>
Is there anything I missed? Only build plugin dependencies are not resolved where as project dependencies are getting resolved from our internal repository.
It is the default behavior of maven.
When defining <repository> .... </repository> make sure to override the <id>central</id> with your internal repository. If you don't do so, maven will still contact maven central to resolve dependencies and not work without proper proxy settings if you are behind a VPN. The below listing will fetch all your deps from your internal repository.
<repositories>
<repository>
<id>central</id>
<name>Internal Release Repository</name>
<url>https://archiva.global.com/repository/internal</url>
</repository>
<repository>
<id>archiva.snapshots</id>
<name>Internal Snapshots Repository</name>
<url>https://archiva.global.com/repository/snapshots</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
For downloading the plugins from your internal repository
<pluginRepositories>
<pluginRepository>
<id>central</id>
<name>Central Internal Repo</name>
<url>https://archiva.global.com/repository/internal</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
</pluginRepository>
I want to download spring-native dependency from maven mirror as it is not in my third party mirror.I tried to do it by including maven mirror in my settings.xml file,but it doesn't work.
Settings.xml file-
<?xml version="1.0" encoding="UTF-8"?>
<settings>
<mirrors>
<mirror>
<id>artifactory</id>
<mirrorOf>*</mirrorOf>
<url>https://thirdparty.com/artifactory</url>
</mirror>
<mirror>
<id>MavenCentral</id>
<url>https://repo.maven.apache.org/maven2</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
<profiles>
<profile>
<id>artifactory</id>
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>MavenCentral</id>
<url>https://repo.maven.apache.org/maven2/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>artifactory</activeProfile>
</activeProfiles>
</settings>
I added this dependency-
<dependency>
<groupId>org.springframework.experimental</groupId>
<artifactId>spring-native</artifactId>
<version>0.9.2</version>
</dependency>
Issue-
Cannot resolve org.springframework.experimental:spring-native:0.9.2
How can I resolve this?
When you use <mirrorof>*<mirrorof> then you essentially override all other mirrors and repository definitions. To exclude repositories from the mirror, use
*,!otherrepo
I use for Eclipse a maven settings.xml that has a 3rd-party Artifactory location from which Maven artefacts are retrieved.
We added now an own Artifactory which hosts artefacts not contained in the former Artifactory.
We added new profiles to the settings.xml and activated them.
What happens now, if artefacts shall be retrieved that are only in the new one, the maven build fails with an artefact not found exception.
Looking through the debug-output it seems like Maven never tries to access the new location.
As test, we deactivated the profiles of the 3rd-party Artifactory. Now the debug-log shows that Maven tries to access our Artifactory (but only if there are no other locations than ours).
Has someone an idea why the new Artifactory is ignored if the other profiles are active?
Below is my settings.xml, the upper two "ltl-*" profiles are the new ones which seems to be not used.
<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">
<profiles>
<profile>
<id>ltl-releases</id>
<repositories>
<repository>
<id>ltl-releases</id>
<url>http://134.91.18.140:8081/artifactory/releases</url>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</profile>
<profile>
<id>ltl-snapshots</id>
<repositories>
<repository>
<id>ltl-snapshots</id>
<url>http://134.91.18.140:8081/artifactory/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
<profile>
<id>ukp-oss-releases</id>
<repositories>
<repository>
<id>ukp-oss-releases</id>
<url>http://zoidberg.ukp.informatik.tu-darmstadt.de/artifactory/public-releases/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>ukp-oss-releases</id>
<url>http://zoidberg.ukp.informatik.tu-darmstadt.de/artifactory/public-releases/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
<profile>
<id>ukp-oss-snapshots</id>
<repositories>
<repository>
<id>ukp-oss-snapshots</id>
<url>http://zoidberg.ukp.informatik.tu-darmstadt.de/artifactory/public-snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>ltl-releases</activeProfile>
<activeProfile>ltl-snapshots</activeProfile>
<activeProfile>ukp-oss-releases</activeProfile>
<!-- Uncomment the following entry if you need SNAPSHOT versions. -->
<activeProfile>ukp-oss-snapshots</activeProfile>
</activeProfiles>
</settings>
I get the following error
[WARNING] The POM for com.westgroup.caesar.uuid:wguuidJava:jar:1.0 is missing, no dependency information available
[WARNING] The POM for charliedog:argv:jar:0.0.1 is missing, no dependency information available
[WARNING] The POM for com.oracle:classes12:jar:10.1.0.5.0 is missing, no dependency information available
But these jars and pom files are downloaded into my local repository from central repository Nexus. When I run the command mvn clean install, I get the above error.
Maven settings.xml file:
<server>
<id>releases</id>
<username>abc</username>
<password>abc</password>
</server>
<server>
<id>snapshots</id>
<username>abc</username>
<password>abc</password>
</server>
<server>
<id>thirdparty</id>
<username>abc</username>
<password>abc</password>
</server>
<mirror>
<id>nexus-public-snapshots</id>
<mirrorOf>public-snapshots</mirrorOf>
<url>http://maven.int.westgroup.com:8081/nexus/content/groups/public-snapshots</url>
</mirror>
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<name>Nexus Public Mirror</name>
<url>http://maven.int.westgroup.com:8081/nexus/content/groups/public</url>
</mirror>
<mirror>
<id>nexus-third-party</id>
<mirrorOf>third-party</mirrorOf>
<url>http://maven.int.westgroup.com:8081/nexus/content/repositories/thirdparty/</url>
</mirror>
<profiles>
<profile>
<id>development</id>
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
<profile>
<!--this profile will allow snapshots to be searched when activated-->
<id>public-snapshots</id>
<repositories>
<repository>
<id>public-snapshots</id>
<url>http://public-snapshots</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>public-snapshots</id>
<url>http://public-snapshots</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
<profile>
<!--this profile will allow snapshots to be searched when activated-->
<id>third-party</id>
<repositories>
<repository>
<id>third-party</id>
<url>http://thirdparty</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>third-party</id>
<url>http://thirdparty</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<!-- activeProfiles
| List of profiles that are active for all builds.
|-->
<activeProfiles>
<activeProfile>development</activeProfile>
<activeProfile>public-snapshots</activeProfile>
<activeProfile>third-party</activeProfile>
</activeProfiles>
I have uploaded these missing jars into Nexus repository into third-party repository.
wguuidJava jar and pom file in my local repository
Could you please let me know if I am missing any configuration in the settings.xml file?
Everything is fine. You have a WARNING, not an ERROR.
This warning is related to how the jar was built and uploaded to the repository. It does not affect functionality.
I hope this helps.
How can i use selenium and sikuli in one pom.xml ?
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.45.0</version>
</dependency>
<dependency>
<groupId>com.sikulix</groupId>
<artifactId>sikulixapi</artifactId>
<version>1.1.0-SNAPSHOT</version>
</dependency>
sikuli is in :
<repository>
<id>com.sikulix</id>
<name>com.sikulix</name>
<url>https://oss.sonatype.org/content/groups/public</url>
<layout>default</layout>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
but adding this repo, makes maven to look there for selenium too
is it possible to link two different dependencies from two different repositories ?
Maven looks for artifacts (selenium, sikulixapi, ..) in all defined repositories.
You can define two: com.sikulix and the standard one:
<repositories>
<repository>
<id>com.sikulix</id>
<name>com.sikulix</name>
<url>https://oss.sonatype.org/content/groups/public</url>
<layout>default</layout>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
<repository>
<id>central</id>
<name>Maven Repository Switchboard</name>
<layout>default</layout>
<url>http://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>