I would like to maintain all my java project's packages in a single repository. I'm using Github actions for this. I added the repository of the destination repo inside the pox.xml file.
<profiles>
<profile>
<id>github</id>
<activation>
<property>
<name>useGitHubPackages</name>
<value>true</value>
</property>
</activation>
<distributionManagement>
<repository>
<id>github</id>
<name>GitHub Packages</name>
<url>https://maven.pkg.github.com/******/test-platform</url>
</repository>
</distributionManagement>
</profile>
<profile>
<!-- We only need GitHub packages during releases as syncing to central is too slow. -->
<id>github-releases</id>
<repositories>
<repository>
<id>github</id>
<name>GitHub Packages</name>
<url>https://maven.pkg.github.com/*****/test-platform</url>
</repository>
</repositories>
</profile>
</profiles>
I'm also using the settings.xml file and added the Personal Access Token as secrets to the repository. The token has scope as repo and write:packages. But when publishing the package I'm getting the following error. Anyone can help with this?
Error: Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project demoproject: Failed to deploy artifacts: Could not find artifact com.example:demoproject:jar:3.0.1 in github (https://maven.pkg.github.com/*****/test-platform) -> [Help 1]
I would like to maintain the demoproject package inside the test-platform repository.
Thankyou.
Related
I have some java projects which used maven build and upload artifact to nexus. It's working well. Now there are some changes in my company process so I need to upload artifact to 2 remote repository:
Nexus
Gitlab package registry
I try to define multiple profiles in pom.xml but it also pick 1 profile to deploy. Anyone have exp about this, please advise me
<profiles>
<profile>
<id>profile-1</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>profile-1-repo</id>
...
</repository>
</repositories>
</profile>
<profile>
<id>profile-2</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>profile-2-repo</id>
...
</repository>
</repositories>
</profile>
...
mvn deploy -P profile-1,profile-2...
I have a private repository in GitLab (it's in a group, and I have a Developer role) which I want to add as a dependency for my Maven project.
I've been looking for a while and all I found was that I have to add the following to my pom.xml:
<repositories>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/.../packages/maven</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/.../packages/maven</url>
</repository>
<snapshotRepository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/.../packages/maven</url>
</snapshotRepository>
</distributionManagement>
However, I have no idea how to add the dependency itself (with the groupId and stuff) and I'm not sure how to do authentication to allow Maven to download the project. I've seen something about Personal Access Tokens in GitLab, but I'm not sure how to set that up (I assume I'd only need read-only access?).
First, a few pre-requisites. Since you mentioned you're using a private repository, you'll need to have at least GitLab Silver (hosted on gitlab.com) or GitLab Premium (self-hosted) in order to use the GitLab Maven Packages repository. Also, if you're self-hosted, you'll need to be on GitLab 11.3 or later (should be out this time next week), and have packages_enabled set to true (see Enabling the Packages repository).
For private projects, you'll need a Personal Access Token. The token should have the api scope for Maven to upload artifacts to GitLab. Once you have the token, you configure your settings.xml like this.
<settings>
<servers>
<server>
<id>gitlab-maven</id>
<configuration>
<httpHeaders>
<property>
<name>Private-Token</name>
<value>REPLACE_WITH_YOUR_PERSONAL_ACCESS_TOKEN</value>
</property>
</httpHeaders>
</configuration>
</server>
</servers>
</settings>
In pom.xml, where you have the ellipses, you need to fill in your project ID. To find the ID, just visit the front page of your project on GitLab. It's shown near the top of the pages, just after the name and description of your project. For example, take a look at the mvn-example sample project. Its project ID is 8377576. That goes in the URL.
<repositories>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/8377576/packages/maven</url>
</repository>
</repositories>
The mvn-example project's pom.xml file shows a completed example.
With all that set up, you should be able to upload artifacts with mvn deploy.
First of all you should go to your projects "Packages and Registries" it is on the left menu of your Gitlab user interface and find there package registry button(if you can't see it just ask your system administrator) and just leave that tab open and wait for future instructions.
Be aware that if you work in a company that has Gitlab domain, everywhere that I write "https://gitlab.com", you should write your company's gitlab domain.
After that you should generate your "Private-Token" by going to "https://gitlab.com/profile" -> "access tokens" and select api check box and give a name to your token for example "test token" and then press generate.
After that in your java project create file "settings.xml" near your pom.xml and paste there following piece of code that is below and write there your token that you just generated. This settings.xml is required both for uploading and installing artifact.
<settings>
<servers>
<server>
<id>gitlab-maven</id>
<configuration>
<httpHeaders>
<property>
<name>Private-Token</name>
<value>your token</value>
</property>
</httpHeaders>
</configuration>
</server>
</servers>
</settings>
After that go to Gitlab's user inreface and copy your project's id from there. See screenshot:
After that paste following code that is below in your pom.xml. This must be done in the project that should be uploaded in Gitlab's "package registry"
<distributionManagement>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/project_id/packages/maven</url>
</repository>
<snapshotRepository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/project_id/packages/maven</url>
</snapshotRepository>
</distributionManagement>
For uploading artifact open terminal in your ide and paste following command:
mvn deploy -s settings.xml
After that go to "package registry" of your project in Gitlab user interface and see there uploaded artifact.
For installing the settings.xml also needed, and also paste following piece of code that is below in your pom.xml
<repositories>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/project_id/packages/maven</url>
</repository>
</repositories>
And in your terminal call: mvn install -s settings.xml or mvn dependency:get -Dartifact={groupId}:{artifactId}:{version}
If there is an error while installing, don't worry, got to your local computer's .m2 folder, find that folder with containing new created artifact(jar), delete it and then go and call the same terminal command once again.
To use your private repository as maven dependency go to your package Registry and click on the package(com/example/demo)
you will see the instruction to add the dependency.
You need to add tag with correct dependency and and tag.
if you will mention private repository url in both and , it will pull and push the artefact from the private repository.
If you want to use the private repository to only download the dependency and push your artifact to the current project registry, then you need to add the and tag of the private repository and tag will the current project one.
Scenario 1:-
<dependency>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/36104875/packages/maven</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/36104875/packages/maven</url>
</repository>
<snapshotRepository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/36104875/packages/maven</url>
</snapshotRepository>
</distributionManagement>
2nd scenario:-
<dependency>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/36104875/packages/maven</url>
</repository>
</repositories>
<distributionManagement>
<snapshotRepository>
<id>gitlab-maven</id>
<url>${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/maven</url>
</snapshotRepository>
<repository>
<id>gitlab-maven</id>
<url>${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/maven</url>
</repository>
</distributionManagement>
I have added a jar file to my local maven repository by mvn install: install-file which works fine on my local machine. This is the dependency in my pom:
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>${oracle.connector.version}</version>
</dependency>
When running mvn clean install on my machine, everything works just fine.
Now I have a local jenkins instance running (on a Windows machine) which should build my project. The build runs into an error and jenkins says:
Could not find artifact com.oracle:ojdbc6:jar:11.2.0 in mirror1 (http://repo.maven.apache.org/maven2) -> [Help 1]
The project settings for jenkins looks like this:
<?xml version="1.0" encoding="UTF-8" ?>
<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>${user.home}/.m2/repository</localRepository>
<servers>
<server>
<id>nexusReleases</id>
<username>deployment</username>
<password>deployment123</password>
</server>
<server>
<id>nexusSnapshots</id>
<username>deployment</username>
<password>deployment123</password>
</server>
</servers>
<mirrors>
<mirror>
<id>mirror1</id>
<mirrorOf>*</mirrorOf>
<name>Maven2 official repo</name>
<url>http://repo.maven.apache.org/maven2</url>
</mirror>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:8081/repository/maven-public/</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<!--Enable snapshots for the built in central repo to direct -->
<!--all requests to nexus via the mirror -->
<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>
</profiles>
<activeProfiles>
<!--make the profile active all the time -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>
And of course I've double checked the repository directory in .m2 . The ojdbc6.jar is there.
So what's wrong with my setup?
You might want to check what Jenkins uses as its local repository.
Go to Jenkins verwalten (Manage Jenkins)
Under Maven-Projekt-Konfiguration (Maven project configuration), there should be a setting where the .m2 repository for Jenkins is located.
If that was not the same repository you were using locally, that would explain your error.
Edit: There is also an option for each job whether or not to use a "private repository". That repository will be specific to that job and not share artifacts with any other.
I had the same issue with ojdbc8.jar. The build failed with this dependency in my pom.xml.
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc8</artifactId>
<version>19.3</version>
</dependency>
I copied the ojdbc8.jar to the Jenkins maven repository. After renaming it to ojdbc8-19.3.jar my build was successful.
Perhaps this helps someone else.
Use the following dependency:
<dependency>
<groupId>com.oracle.ojdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>19.3.0.0</version>
</dependency>
I'm trying to connect to a mysql database in java and so I have to add mysql-connector-java:jar to my eclipse project. The integration with maven is not working though.
Here is what I have in my settings.xml:
<profile>
<id>default</id>
<properties>
<mvn.path>.../maven-3.0.4/bin/mvn.bat</mvn.path>
<javac.5>...bin/javac.exe</javac.5>
<javac.6>..../javac.exe</javac.6>
</properties>
<repositories>
<repository>
<id>central-repository</id>
<name>OSS central Maven Release Repository</name>
<url>https://oss.sonatype.org/content/repositories/releases</url>
</repository>
<repository>
<id>public-repository-main</id>
<name>Central Repository</name>
<url>https://repo1.maven.org/maven2</url>
</repository>
<repository>
<id>public-repository</id>
<name>OSS Maven Release Repository</name>
<url>https://oss.sonatype.org/content/groups/public</url>
</repository>
</repositories>
</profile>
<interactiveMode>true</interactiveMode>
<!-- offline
| Determines whether maven should attempt to connect to the network when executing
| a build.
| This will have an effect on artifact downloads, artifact deployment, and others.
|
| Default: false <offline>false</offline> -->
<offline>false</offline>
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://xxxx:8083/nexus/content/groups/public</url>
</mirror>
And here is the error I get when I try to a mvn clean install
Failure to find mysql:mysql-connector-java:jar:5.0.5 in
http://xxxx:8083/nexus/content/groups/public
How can I force nexus to download the artifact from my public repositories to nexus? Do I have to add it manually?
You need to tell maven to use your maven repository. To do this, modify $HOME/.m2/settings.xml as follows:
<?xml version="1.0" encoding="UTF-8"?>
<settings 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/settings-1.0.0.xsd">
<mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://xxxx:8083/nexus/content/groups/public</url>
</mirror>
</mirrors>
<proxies></proxies>
<servers></servers>
<pluginGroups></pluginGroups>
<profiles>
<profile>
<id>nexus</id>
<!--Enable snapshots for the built in central repo to direct -->
<!--all requests to nexus via the mirror -->
<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>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>
The nexus profile is configured to download from the central repository with a bogus URL of http://central.
This URL is overridden by the mirror setting in the same settings.xml file to point to the URL of your single Nexus group. The nexus group is then listed as an active profile in the activeProfiles element.
Suppose you have repository Central that has repository path http://xxxx:8083/nexus/content/repositories/central and also point Remote Storage Location to http://repo1.maven.org/maven2/ you can change http://central to http://xxxx:8083/nexus/content/repositories/central or http://repo1.maven.org/maven2/.
in your pom.xml, use below dependency to getting mysql-connector.
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.33</version>
</dependency>
See also: Getting started with Nexus maven repository manager
Hope this help.
Is there a chance that you have included two different versions for mysql-connector-java?
I used to have an error like that, it turned out I had accidentally included another version, so this specific version was not accessed (it was a transitive dependency, which for peculiar reasons I could not exclude). I moved the dependency in the beginning of all other dependencies (in your case it might be in the end),and it worked. Theoretically having two versions of same dependency should not throw an error.
Here are the available versions of MySQL connector
http://mvnrepository.com/artifact/mysql/mysql-connector-java , click on any version, it will give your the dependency.
I would like to create a new Maven project in Eclipse using an archetype using the New Maven Project wizard. At the "Select an Archetype" step, I have three catalogs to choose from: Nexus Indexer, Internal and Default Local. I don't understand where the content for these catalogs should be coming from. If I click on the "Configure" button, they are all greyed out and I can't modify them.
Only the Internal catalog has any archetypes listed in it. Where are these archetypes coming from? It's not from my local Maven repository because the group/artifacts are not in it (and archetypes in the repo are not listed).
Why is the Nexus Indexer list empty? I've read some posts that the Nexus index needs to be updated, but not how to do this. Is this different than the repository indexes (which are scheduled to be updated daily).
As you can see, I'm a little confused about the whole catalog business and how Maven, m2eclipse and Nexus interact. Any clarification is most welcome!
My setup:
Eclipse: Helios Service Release 2 (Build id: 20110218-0911)
Apache Maven 3.0.3
m2eclipse: 0.12.1.20110112-1712 (set up to use external Maven install)
Sonatype Nexus™ Open Source Edition, Version: 1.9.0.2
My local Maven settings.xml looks like this:
<settings>
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://myserver:8080/nexus/content/groups/public</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<!--Enable snapshots for the built in central repo to direct -->
<!--all requests to nexus via the mirror -->
<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>
</profiles>
<activeProfiles>
<!--make the profile active all the time -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
<servers>
<server>
<id>my-snapshots</id>
<username>user</username>
<password>password</password>
</server>
<server>
<id>my-releases</id>
<username>user</username>
<password>password</password>
</server>
</servers>
</settings>
The default archetype catalog can contain new archetypes. It's a manual process, you've to add them to a custom .xml file within your ~/.m2 directory.
For more information : http://maven.apache.org/archetype/maven-archetype-plugin/specification/archetype-catalog.html
And for reference, here's a template archetype-catalog.xml
<?xml version="1.0" encoding="UTF-8"?>
<archetype-catalog>
<archetypes>
<archetype>
<groupId>com.spedge</groupId>
<artifactId>archetype-application-custom-filter</artifactId>
<version>1.0-SNAPSHOT</version>
</archetype>
</archetypes>
</archetype-catalog>
Additionally, here's a good link on SO about Archetypes : What are the URLs of all the Maven Archetype catalogs that you know about?