I am new to maven and I am trying to create a single pom file for both linux and windows. For dependency resolution, I have 2 p2 repositories. 1 for windows and the other is for linux.
I also have a target definition (.target) in which I am adding all external repositories for dependecy resolution.
Is there a way that I can add/activate a repository location per OS? Below is my trial.
Using maven pom profiles:
In this trial, I added all my repositories (common for windows and linux) to the target definition. I then created 2 new profiles and added the OS-specific p2 repo like so
<profile>
<id>Linux</id>
<activation>
<activeByDefault>false</activeByDefault>
<os><name>linux</name></os>
</activation>
<repositories>
<repository>
<id>p2_lin</id>
<url>http://example.com/data/LINUX_P2</url>
<layout>p2</layout>
</repository>
</repositories>
</profile>
<profile>
<id>Windows</id>
<activation>
<activeByDefault>false</activeByDefault>
<os><name>win32</name></os>
</activation>
<repositories>
<repository>
<id>trace_p2_win</id>
<url>http://example.com/data/WINDOWS_P2</url>
<layout>p2</layout>
</repository>
</repositories>
</profile>
While calling maven, I add this profile to the parameters mvn clean install -PWindows,Test
Unfortunately, the above configuration gives an unsatisfied dependency.
But when I remove this section from the parent pom file and add the correct repository (example: >http://example.com/data/WINDOWS_P2) to the target definition without the other one, everything seems to be fine.
Related
I want to deploy to a private Maven repository only if there is a defined profile.
Is this possible? And how can I do it?
put the repository into profile
<profiles>
<profile>
<id>test</id>
<distributionManagement>
<repository>
<id>repsy</id>
<name>My Private Maven Repository on Repsy</name>
<url>https://repo.repsy.io/mvn/username/reponame</url>
</repository>
</distributionManagement>
</profile>
</profiles>
you can execute :mvn deploy -P test,it will use the repo in the test profile.
Maybe you can use the skip property described here: https://maven.apache.org/plugins/maven-deploy-plugin/deploy-mojo.html#skip
mvn deploy -Dmaven.deploy.skip=true
If I have a GitHub organisation ACME, and we have two repositories Repository1 and Repository2 which both publish packages to GitHub packages via Maven, is there a way to have both packages be added in a single Maven repository, as an organisation owner?
For instance,
<!-- settings.xml -->
<profiles>
<profile>
<id>github</id>
<repositories>
<repository>
<id>github</id>
<name>GitHub OWNER Apache Maven Packages</name>
<url>https://maven.pkg.github.com/ACME</url>
</repository>
</repositories>
</profile>
</profiles>
I have tried looking through various repos around, however i could not find one that contains the jar file for this dependency:
<dependency>
<groupId>com.oracle.java</groupId>
<artifactId>jre</artifactId>
<version>1.8.0_131</version>
</dependency>
Error i got: Could not resolve dependencies for project com.blackducksoftware.test:example-maven-travis:jar:0.1.0-SNAPSHOT: Could not find artifact com.oracle.java:jre:jar:1.8.0_131 in jboss (http://repository.jboss.org/nexus/content/groups/public-jboss)
Is there a reason why only pom files are in the repo and not the jar file?
How do I get the jar file?
From mvnrepository.com:
Note: this artifact it located at Alfresco repository (https://artifacts.alfresco.com/nexus/content/repositories/public/)
So you need to add a profile entry to your settings.xml file.
Example:
<profile>
<id>alfresco-repo</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>alfresco-repo</id>
<name>Alfresco Repository</name>
<url>https://artifacts.alfresco.com/nexus/content/repositories/public/</url>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>
</profile>
I need to build and release projects using Jenkins,
on a server with no access to maven central, and even, with no access to Nexus.
Given that I have access to maven-central on dev machines,
to fill the maven local_repository, I could do
mvn dependency:resolve-plugins dependency:go-offline
to then copy the local_repository on the linux server.
Then, to get ride of a Non-resolvable parent POM error,
as described here, I filled the specific profiles for both windows (dev) and linux (jenkins) with faked central profile to override the maven-central reference made by my parent pom:
<profiles>
<profile>
<id>windows</id>
<activation>
<os>
<family>Windows</family>
</os>
</activation>
<properties> <repository.base.url>file:///c:/maven_distribution_repo/</repository.base.url>
</properties>
</profile>
<profile>
<id>linux</id>
<activation>
<os>
<family>Linux</family>
</os>
</activation>
<properties>
<repository.base.url>file:///appli/Maven_3.1.1_build/maven_distribution_repo/</repository.base.url>
</properties>
<repositories>
<repository>
<id>central</id>
<name>Maven Plugin Repository</name>
<!--<url>http://repo1.maven.org/maven2</url>-->
<url>${repository.base.url}</url>
<releases>
<enabled>false</enabled>
</releases>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<name>Maven Plugin Repository</name>
<!--<url>http://repo1.maven.org/maven2</url>-->
<url>${repository.base.url}</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
That way, mvn -o compile still raise a Non-resolvable parent POM error !,
but using the --legacy-local-repository option suggested here ,
managed to fake the remote repository by using a local one,
and the Non-resolvable parent POM problem disappeared:
mvn --legacy-local-repository compile
Still, a strange error appeared (decribed here):
[ERROR] Failed to execute goal on project myProject: Could not resolve dependencies for project some.package:myProject:war:0.0.7-SNAPSHOT: Failed to collect dependencies at org.jxls:jxls-poi:jar:1.0.11 -> org.jxls:jxls:jar:[2.0.0,): org.jxls:jxls:jar:[2.0.0,) within specified range -> [Help 1]
But it was hiding an earlier warning:
[WARNING] Could not transfer metadata org.jxlsjxls/maven-metadata.xml from/to central (/path):/appli/Maven_3.1.1_build/maven_distribution_repo/org/jxls/jxls/maven-metadata-central.xml (access forbidden)
Using --legacy-local-repository, maven seems to use the distribution repository path as the local libs repository !
I swapped them in the pom:
<profile>
<id>linux</id>
<activation>
<os>
<family>Linux</family>
</os>
</activation>
<properties>
<!--<repository.base.url>file:///appli/Maven_3.1.1_build/maven_distribution_repo/</repository.base.url>-->
<repository.base.url>file:///appli/Maven-3.1.1_build/maven_local_repo/</repository.base.url>
</properties>
...
and had also to copy into the local repository:
all maven-metadata-maven2_central.xml into maven-metadata.xml
using the following bash command:
for file in $(find /appli/Maven-3.1.1_build/maven_local_repo -type f -name 'maven-metadata-maven2_central.xml'); do cp $file $(echo ${file%/*}/maven-metadata.xml); done
And ... BINGO !
BUILD SUCCESSFULL
Seems weird, at later stage, to release:perform into the local lib repository.
Would you have any better and not that painful solution ?
Maven deploy plugin would solve this problem.
mvn deploy -DaltDeploymentRepository=local-temp::default::file://directory/
More Exhaustive example:
# 1. Create temporary folder
tmp_repo=$(mktemp -d systemds-repo-tmp-XXXXX)
# 2. Create a simple settings.xml
cat <<EOF >../tmp-settings-nexus.xml
<settings>
<activeProfiles>
<activeProfile>local-temp</activeProfile>
</activeProfiles>
<profiles>
<profile>
<id>local-temp</id>
<repositories>
<repository>
<id>local-temp</id>
<url>${tmp_repo}</url>
</repository>
</repositories>
</profile>
</profiles>
</settings>
EOF
# 3. deploy to local
mvn --settings ../tmp-settings-nexus.xml -Pdistribution deploy \
-DaltDeploymentRepository=local-temp::default::file://${tmp_repo} \
-Daether.checksums.algorithms='SHA-512,SHA-1,MD5'
You should consider setting up a local repository (for example, Nexus) that will be accessible to your build machine.
This is a very common setup.
It enables you to build without internet connection to the build machine.
I'm trying to activate a profile in my settings.xml by the value of the pom's groupId. To achieve that I have:
<settings>
<profiles>
<profile>
<id>imf</id>
<activation>
<property>
<name>project.groupId</name>
<value>myId</value>
</property>
</activation>
<properties>
. . .
</properties>
</profile>
</profiles>
</settings>
But this doesn't work. Is it not possible to access project properties from settings? The reference material says you can.
Just to verify my use of the property activator element, I conducted a sanity check using a property set from the command line. Indeed, if I pass in -Dproject.groupId=myId to the mvn command line, my activation works. This leads me to believe that the project properties simply aren't available in the settings.xml file.
It looks like your specific requirement cannot be achieved in the way you have tried.
project.groupId as a property name (or key) does not mean anything to maven. maven understands (and expands) ${project.groupId} and similar values in settings.xml or pom.xml.
I had a similar requirement - choosing between profiles depending on the groupId of the project (to choose between remote repositories). Then I noticed that my groupIds are always actually package names in my java class hierarchy. And package names are just simply directories in the filesystem. So my solution to this problem was to use the actication/file/exists tag:
<profiles>
<profile>
<id>client1</id>
<activation>
<activeByDefault>false</activeByDefault>
<file>
<exists>${basedir}/src/main/java/hu/client1</exists>
</file>
</activation>
<repositories>
<repository>
</repository>
</repositories>
</profile>
<profile>
<id>client2</id>
<activation>
<activeByDefault>false</activeByDefault>
<file>
<exists>${basedir}/src/main/java/hu/client2</exists>
</file>
</activation>
<repositories>
<repository>
</repository>
</repositories>
</profile>
<profile>
<id>client3</id>
<activation>
<activeByDefault>false</activeByDefault>
<file>
<exists>${basedir}/src/main/java/com/client3</exists>
</file>
</activation>
<repositories>
<repository>
</repository>
</repositories>
</profile>
</profiles>