I want to avoid putting this part in pom.xml of every project distributed the same way
<distributionManagement>
<repository>
<id>my-id</id>
<name>My deployed artifacts</name>
<url>https://organization.xxx/maven/</url>
</repository>
</distributionManagement>
How to set it globally via maven command or editing setting file?
Cannot be done in settings.xml.
What you can do:
Use a company parent POM that specifies the distributionManagement.
Set a property in the settings.xml and use it in distributionManagement.
Use -DaltDeploymentRepository=... on command line for the build. See also https://maven.apache.org/plugins/maven-deploy-plugin/deploy-mojo.html#altDeploymentRepository
Related
I am trying to point Maven to a local Artifactory (OSS) repo (both on my Mac) so I can build code provided by a vendor. I have created an empty Maven local repo and virtual repo in Artifactory, and can use Generate Settings to create the snippets. My ID and encrypted password seem to be working OK in ~/.m2/settings.xml
I have updated the code's pom.xml file and that seems to be causing Maven to resolve from Artifactory.
No matter how I configure in ~/.m2/settings.xml or in the master settings.xml or with -Dmaven.repo.local, Maven wants to deploy to a disk path to the local repo.
If I specify a partial path, Maven says "Using local repository at " a path consisting of the code's home + the path I said.
If I specify a path starting with a / (root), Maven says "Using local repository at /whatever"
I want to specify "https://localhost/artifactory/reponame" so Maven will deploy there. Artifactory generates snippets that contain that kind of URL. But since a URL doesn't start with a /, Maven insists on prepending the code home location to the URL, which of course is nonsense.
There must be some combo of and or <distributionManagement> <repository> <id>central</id> <name> <url>https://localhost/artifactory/... that makes this work. What am I missing?
pom.xml snippet:
<distributionManagement>
<repository>
<id>central</id>
<name>LocalMac-releases</name>
<url>https://localhost/artifactory/TBX</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>LocalMac-snapshots</name>
<url>https://localhost/artifactory/TBX</url>
</snapshotRepository>
</distributionManagement>
Master settings.xml snippet: localRepository is commented out so it takes the default. When commented in whatever I enter does take effect... combined with ${user.home}.
<!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ${user.home}/.m2/repository
<localRepository>/path/to/local/repo</localRepository>
-->
I'm trying to build an RCP application via Tycho and I receive this error when exporting the product.
I don't really understand the issue, but could it be that the reason why it fails it's because I'm using multiple P2 repositories to retrieve my plugins dependencies?
This is the snipped of the repositories I've defined in my parent POM. The rest is pretty standard Tycho.
<repositories>
<repository>
<id>eclipse-luna</id>
<url>${eclipseLuna}</url>
<layout>p2</layout>
</repository>
<repository>
<id>systems-rc-p2</id>
<url>${systemsRcP2}</url>
<layout>p2</layout>
</repository>
<repository>
<id>systems-snapshots-p2</id>
<url>${systemsSnapshotsP2}</url>
<layout>p2</layout>
</repository>
</repositories>
I found the issue.
Basically for some reason (project needs) I had to change the "sourceDirectory" and the "outputDirectory" of the project, pointing them to the classic "src" and "bin" instead of the Maven default "src/main" and "target".
In particular, what was causing the issue was the redefinition of the <outputDirectory> property and the <directory> one. It looks like Tycho does not like it at all.
In my company's parent POM I specify corporate repositories, that we all use. The URLs contain server name and the path of course. Each time I change the POM I publish a new version.
Now imagine, that the server hosting our repos gets renamed. I can change all URLs in the parent POM (not a problem) and publish a new version with fixed URLs. But I can't change URLs in the existing versions of the parent POM.
This means, that I can't rebuild any artifact from the past.
Is there some standard way to get around this problem? Like:
Central property file
A configuration POM with a fixed 1.0.0-SNAPSHOT version, that get republished on any change?
You never put repositories except for distMngt in your POM. Again -- never. You have burned your POMs forever. This exists in Maven because repo managers did not exist back then. It is bad practice for years now and shall be removed.
Always use a Nexus instance with a repo group. This shall be added to your settings.xml which will mirror everything.
For those who don't believe, I am a long year Maven committer.
Another approach that we employ at work is to replace the URLs in the <distributionManagement> with parameters, like so:
<distributionManagement>
<repository>
<id>my-repo</id>
<name>My Release Repo</name>
<url>${url.deploy.releases}</url>
</repository>
<snapshotRepository>
<id>my-repo</id>
<name>My Release Repo</name>
<url>${url.deploy.snapshots}</url>
</snapshotRepository>
</distributionManagement>
This way, we use settings.xml to control where the artifacts should be deployed. This has the advantage that if you ever migrate a repository (which we did) you only need to update settings.xml for new builds/releases.
If you need to go back to an earlier release and republish (for whatever reason) you just checkout the release tag, set up settings.xml to point to the new repo and do a mvn clean deploy.
If you can't modify settings.xml you can always just copy it, change the copy and point out the new settings file with the -s flag.
This approach also works for <scm> tags.
If you use repositories in your parent pom and may change over time, the best strategy is in the URL or it use ALIAS (DNS, Apache redirect, Rewriting) and especially not the IP address directly , and you do not have to change the address of the repository every time.
Example:
<repositories>
<repository>
<id>myrepo</id>
<url>http://myrepo.me/content/repositories/public/</url>
</repository>
</repositories>
and:
http://myrepo.me/content/repositories/public/ => ip address 1.2.3.4/*/*/
In maven settings, there is an entity which refers the local repository:
<localRepository>~/.m2/repository</localRepository>
When I add another one, like this:
<localRepository>~/another/place</localRepository>
it raises Duplicated tag error.
Can I have multiple local repository or maybe add another direcotry to the local repository?
EDIT
This idea seems a possible answer, too:
mvn -Dmaven.repo.local=/path/to/repo
Yes you can have and you can do it in your POM.xml itself. Below is an example.
<project>
...
<repositories>
<repository>
<id>firstrepo</id>
<name>repo</name>
<url>http://myrepo.my</url>
</repository>
<repository>
<id>secondrepo</id>
<name>repo2</name>
<url>http://myrepo.yours</url>
</repository>
</repositories>
...
</project>
Second Method by creating profile in your settings.xml
For multiple local repositories you can have multiple settings.xml file.
In the command line specify alternate path using
mvn -Dmaven.repo.local=/path/to/repo For more information you can check this link. Hope it helps.
Anyway I can move the distributionManagement part outside the pom
I don't like the idea that my pom.xml contains server location,
Is it possible to move this or server name to settings.xml?
Thanks
<distributionManagement>
<repository>
<id>archiva</id>
<name>archiva Repo</name>
<url>http://ca.server:8080/archiva/repository/snapshots/</url>
</repository>
<snapshotRepository>
<uniqueVersion>false</uniqueVersion>
<id>archiva</id>
<name>archiva Repo</name>
<url>http://ca.server:8080/archiva/repository/snapshots/</url>
</snapshotRepository>
</distributionManagement>
The best idea for this is to put such information into a parent POM (company pom) and use this instead of the settings.xml cause any body who wan't to build needs to change the settings.xml.
Short answer: Yes, you can.
Longer answer: I like the idea too, because I could imagine that the application will be built and distributed on different servers. So I like the following:
Define in the POM the dependencies to other libraries and plugins.
Define in your Maven installation configuration (so it is dependent on the installation, not on the user using that installation) what you have sketched out in your question.
Normally, you need a user-id and password to distribute in a Maven repository, and this is the (only) contents of it:
<settings>
<servers>
<server>
<id>archiva</id>
<username>XXadmin-user-nameXX</username>
<password>XXadmin-passwordXX</password>
</server>
</servers>
</settings>
This should only be on the build server configured by the build manager and not known by everyone. The only thing you have to ensure is that the IDs are the same in both files.