How to use the target folder of another project as target platform repository in a Tycho build? - maven

I am creating an Eclipse plugin in an continuous integration environment. My project contains four child modules as follows
parent
---p2Repository
---eclipseplugin
---feature
---updateSite
During the continuous integration build, first the p2 repository for the dependencies is created. My Eclipse plugin project needs to point to the p2Repository's target folder to get the dependecies. But by providing the following code in the eclipse-plugin POM file is not working:
<repositories>
<repository>
<id>Dependencies</id>
<layout>p2</layout>
<url>file:/../p2Respository/target/repository/</url>
</repository>
</repositories>
Any advice?

The file URL you specified does not represent a relative path, and relative URLs are not supported in the repositories configuration.
But you can simply construct an absolute URL pointing to the sibling project's target folder by using the ${project.baseUri} Maven property:
<repositories>
<repository>
<id>Dependencies</id>
<layout>p2</layout>
<url>file:/${project.baseUri}/../p2Respository/target/repository/</url>
</repository>
</repositories>

Related

Maven: how to purge a custom local repository

Beside the local repository at the default location, I have another local repository with snapshots of a large number of jars of some projects which do not use Maven. It is defined in pom.xml as follows:
<repositories>
<repository>
<snapshots>
<updatePolicy>always</updatePolicy>
</snapshots>
<id>repo</id>
<url>file:///${project.basedir}/path/to/loca/repo</url>
</repository>
</repositories>
and has a distinct <groupId/> so that it is not confused with any other repository. Thanks to this, the main project can be compiled fast and with up-to-date jars on any system which sees its directory.
I would like to purge old snapshots from the custom repository, but
mvn dependency:purge-local-repository -DlocalRepositoryPath=./path/to/local/repo
purges the local repository at the default location, the custom one is left untouched.
How to purge only the repository in the custom directory?

what is the error when integrating maven with Struts 1.3 with local project libraries?

I have some local jar files in my 'projectBaseDir/lib' location and i have added the directory with the following maven command
<repositories>
<repository>
<id>mylibid</id>
<url>file://${project.basedir}/lib</url>
</repository>
</repositories>
still, the following command shows that it doesn't find any library / showing errors.
mvn clean install
Here is a screenshot -
Create a new folder, let's say local-maven-repo at the root of your Maven project.
Just add a local repo inside your of your pom.xml:
<repositories>
<repository>
<id>local-maven-repo</id>
<url>file:///${project.basedir}/local-maven-repo</url>
</repository>
</repositories>
Then for each external jar you want to install, go at the root of your project and execute:
mvn deploy:deploy-file -DgroupId=[GROUP] -DartifactId=[ARTIFACT] -Dversion=[VERS] -Durl=file:./local-maven-repo/ -DrepositoryId=local-maven-repo -DupdateReleaseInfo=true -Dfile=[FILE_PATH]

Maven Tycho: Cannot add artifact descriptor which has not been created by this repository

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.

Installing a maven project with a dependency on a parent

I have a collection of related projects that inherit from a common maven project.
Since they are still in alpha release, they all (including the parent) are deployed in the Sonatype snapshots repository, instead of Maven central.
The configuration for accessing the maven central is in the parent project of my application.
So its POM specifies as its parent:
...
<parent>
<groupId>org.sonatype.oss</groupId>
<artifactId>oss-parent</artifactId>
<version>7</version>
</parent>
...
And set the corresponding repository at Sonatype:
...
<repositories>
<repository>
<id>snapshots-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
...
So the children projects do not have to repeat this configuration.
The parent also provides many other things that are common to all my projects.
Currently I keep all these projects in unrelated directories.
Now, if a user of my application checkout one of my projects and attempt to install it with mvn install, he will receive the error: Non-resolvable parent POM: Could not find artifact ...
This makes sense to me, since the project cannot access the Sonatype repository (e.g., for downloading the parent) since it is precisely the parent the one that contains how to connect to such repository.
I do not want to request the user to install first the parent project, since he should be able to install what he needs in just one single step.
Then what is the recommended way to distribute my libraries so the user can install any of them with one single command ?
It occurs to me that I could include the parent POM in each of the projects (for example, using git submodules) so the parent can be resolved locally. But I am wondering if this is the best way to organize this (?). Any better alternative is appreciated.
UPDATE
I added this to my ~/.m2/settings.xml so the parent POM could be resolved in the Sonatype snapshots repository. Apparently it is working fine and the parent POM is resolved as any other dependency.
<profiles>
<profile>
<id>allow-snapshots</id>
<activation><activeByDefault>true</activeByDefault></activation>
<repositories>
<repository>
<id>snapshots-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
</profile>
</profiles>
If you want to keep it to one step install than you have to list enough information in the project pom, i.e. either:
no parent pom, put all the information into each project pom
tell maven where to find your other projects. List the sonatype shnapshot repo in each project file.
A repository manager only helps those with access to it. That is ok if the users are in one organisation. Using the sonatype repository reaches a wider circle.

Parent pom not resolvable unless I add repo to child pom - conundrum

I want to include a parent in a project pom, containing distribution management and repositories. As one would expect.
When I mvn package the child, maven is unable to resolve the parent pom, unsurprisingly.
I can make it resolve the parent by adding my internal nexus repository to the child pom. But this sounds like eggs laying chickens - I'm telling the child something it should know from the parent. I would have to add this repo to every child pom that has a parent.
How can I avoid this?
As khmarbaise wrote, you need to define your repositories in a profile in your settings.xml (this seems somewhat weird, but is actually the only feasible way):
<profiles>
<profile>
<id>repos</id>
<repositories>
<repository>
<id>my-local-repo</id>
<name>Projektserver Snapshots</name>
<url>http://my-server/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<checksumPolicy>fail</checksumPolicy>
<updatePolicy>daily</updatePolicy>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>repos</activeProfile>
</activeProfiles>
Depending on your actual config, you would also include mirror setting and might call your local nexus central.
Sounds like the parent has been deployed to your internal nexus repository so it picks it up from there once you add in the distribution management and repository details.
To make it pick it up from your local copy. First ensure the versions match. Then navigate to the parent and run mvn clean install. This will push the parent pom to your local maven repo.
You may also get round this by ensuring you have added the releativePath element to the parent details in the child pom, you may not need to manually build the parent then but im not 100% sure and havent tested that.
The only things which should defined in your pom is distributionManagement the repositories should be defined in settings.xml instead.

Resources