Issue pulling package from Gitlab Package Registry Maven - java

I try to pull packages from Gitlab Package Registry, but get error:
Could not find group:package:0.0.18-SNAPSHOT.
This package is really exist in package registry
Can anybody help?
am i missing something?
I've tried with gradle:
build.gradle:
repositories {
mavenCentral(),
maven {
url "https://gitlab.com/api/v4/groups/<group-id>/-/packages/maven"
name "GitLab"
credentials(HttpHeaderCredentials) {
name = "<deploy-token-username>"
value = "deploy-token-value"
}
authentication {
header(HttpHeaderAuthentication)
}
}
}
dependencies {
implementation("<group>:<package>:0.0.18-SNAPSHOT")
}
And with maven:
pom.xml:
<repositories>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/groups/<group-id>/-/packages/maven</url>
</repository>
</repositories>
<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>
<dependencies>
<dependency>
<groupId>group</groupId>
<artifactId>package</artifactId>
<version>0.0.18-SNAPSHOT</version>
</dependency>
</dependencies>
.../.m2/settings.xml:
<settings>
<servers>
<server>
<id>gitlab-maven</id>
<configuration>
<httpHeaders>
<property>
<name>deploy-token-username</name>
<value>deploy-token-value</value>
</property>
</httpHeaders>
</configuration>
</server>
</servers>
</settings>

Related

How to build maven project both Snapshot and Release build simultaneously

I have a requirement to build both Snapshot versions and Release build at a time.
To build snapshot versions I did like this
<groupId>com.abc.xyz</groupId>
<artifactId>service</artifactId>
<version>1.0.3-SNAPSHOT</version>
<distributionManagement>
<snapshotRepository>
<id>mvn-git-repo</id>
<uniqueVersion>true</uniqueVersion>
<name>maven git repository</name>
<url>file:/home/mvn-github-repo/snapshot</url>
</snapshotRepository>
</distributionManagement>
To build release versions,
<groupId>com.abc.xyz</groupId>
<artifactId>service</artifactId>
<version>1.0.3</version>
<distributionManagement>
<repository>
<id>mvn-git-repo</id>
<uniqueVersion>true</uniqueVersion>
<name>maven git repository</name>
<url>file:/home/mvn-github-repo/release</url>
</repository>
</distributionManagement>
Is it possible to make both together, so that it should generate snapshot version and as well release version jars at a time and deploy in respective repositories.If possible what is the version I should keep in pom ?
You use profile to define the version and repo, like this
<version>${buildVersion}</version>
.
.
.
<profiles>
<profile>
<id>snapshot-repo</id>
<activation>
<property>
<name>snapshot</name>
<value>true</value>
</property>
</activation>
<properties>
<buildVersion>1.0.3-SNAPSHOT</buildVersion>
</properties>
<distributionManagement>
<repository>
</repository>
<snapshotRepository>
</snapshotRepository>
</distributionManagement>
</profile>
<profile>
<id>git-repo</id>
<activation>
<property>
<name>!snapshot</name>
</property>
</activation>
<properties>
<buildVersion>1.0.3</buildVersion>
</properties>
<distributionManagement>
<repository>
</repository>
<snapshotRepository>
</snapshotRepository>
</distributionManagement>
</profile>
Then build by with -Dsnapshot=true

Error trying to import oracle jdbc7 driver with Maven

I cannot import the jdbc7 oracle driver with maven, I did everything like in the tutorial Oracle Blogs but I received the follow error:
Could not resolve dependencies for project
com.jp:database_connection_app:jar:0.0.1: Failed to collect
dependencies at com.oracle.jdbc:ojdbc7:jar:12.1.0.2: Failed to read
artifact descriptor for com.oracle.jdbc:ojdbc7:jar:12.1.0.2: Could
not transfer artifact com.oracle.jdbc:ojdbc7: pom:12.1.0.2 from/to
maven.oracle.com (https://maven.oracle.com): unexpected end of stream
on Connection{maven.oracle.com:443, proxy=HTTP # /myProxyIP:myPort
hostAddress=hostAddressIP cipherSuite=none protocol=http/1.1}
(recycle count=0): \n not found: size=0 content=... ->
A special case to me is that I'm in behind a proxy but I already configure the settings.xml file and maven can download all the dependencies except the JDBC.
In the tutorial mentioned, I didn't understand which information shall be hier...
<basicAuthScope>
<host>ANY </host>
<port>ANY </port>
<realm>OAM 11g </realm>
</basicAuthScope>
Maybe this is the error source.
Here is my settings.xml...
<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
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>${user.home}/.m2/repository</localRepository>
<interactiveMode>true</interactiveMode>
<usePluginRegistry>false</usePluginRegistry>
<offline>false</offline>
<pluginGroups/>
<servers>
<server>
<id>maven.oracle.com</id>
<username>myUsername</username>
<password>My_Encripted_Password</password>
<configuration>
<basicAuthScope>
<host>ANY</host>
<port>ANY</port>
<realm>OAM 11g</realm>
</basicAuthScope>
<httpConfiguration>
<all>
<params>
<property>
<name>http.protocol.allow-circular-redirects</name>
<value>%b,true</value>
</property>
</params>
</all>
</httpConfiguration>
</configuration>
</server>
</servers>
<mirrors>
<mirror>
<id>UK</id>
<name>UK Central</name>
<url>http://uk.maven.org/maven2</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
<proxies>
<proxy>
<id>default</id>
<active>true</active>
<protocol>http</protocol>
<host>myProxy</host>
<port>myPort</port>
<username>myUsername</username>
<password>myPassword</password>
<nonProxyHosts>*.google.com</nonProxyHosts>
</proxy>
</proxies>
<profiles/>
<activeProfiles/>
</settings>
Here is my POM...
<dependencies>
<dependency>
<groupId>com.oracle.jdbc</groupId>
<artifactId>ojdbc7</artifactId>
<version>12.1.0.2</version>
</dependency>
<dependency>
<groupId>com.oracle.jdbc</groupId>
<artifactId>ucp</artifactId>
<version>12.1.0.2</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>maven.oracle.com</id>
<name>oracle-maven-repo</name>
<url>https://maven.oracle.com</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>maven.oracle.com</id>
<name>oracle-maven-repo</name>
<url>https://maven.oracle.com</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
</pluginRepository>
</pluginRepositories>
The settings-security.xml is created under the same path of the settings.xml
Thanks for the help.
I couldn't import the library like I wanted, then I had to search for another solution:
Download the Jar from Oracle Web Site
Include Jar to maven local repository. Learned from Mkyong Web Site
Update Pom with the dependency
If someone have another idea, I will be happy to know that.

Deployment failed: repository element was not specified in the POM inside distributionManagement element [duplicate]

I am trying to run the command, mvn release:perform, but I get this error:
Failed to execute goal
org.apache.maven.plugins:maven-deploy-plugin:2.5:deploy
(default-deploy) on project git-demo:
Deployment failed: repository element
was not specified in the POM inside
distributionManagement element or in
-DaltDeploymentRepository=id::layout::url
parameter
Here's my pom.xml file:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sonatype.blog</groupId>
<artifactId>git-demo</artifactId>
<packaging>jar</packaging>
<version>1.1-SNAPSHOT</version>
<name>git-demo</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<scm>
<connection>scm:git:git#github.com:Christian-Achilli-KP/git-demo.git</connection>
<url>scm:git:git#github.com:Christian-Achilli-KP/git-demo.git</url>
<developerConnection>scm:git:git#github.com:Christian-Achilli-KP/git-demo.git</developerConnection>
</scm>
<distributionManagement>
<!-- use the following if you're not using a snapshot version. -->
<repository>
<id>localSnap</id>
<name>RepositoryProxyRel</name>
<url>http://127.0.0.1:8080/nexus/content/repositories/releases/</url>
</repository>
<!-- use the following if you ARE using a snapshot version. -->
<snapshotRepository>
<id>MylocalSnap</id>
<name>RepositoryProxySnap</name>
<url>http://127.0.0.1:8080/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.1</version>
</plugin>
</plugins>
</build>
</project>
Actually I can see the
repository
declaration inside the
distributionManagent
tag.
Here's my settings.xml:
<settings>
<servers>
<server>
<id>localSnap</id>
<username>deployment</username>
<password>****</password>
</server>
<server>
<id>MylocalSnap</id>
<username>deployment</username>
<password>****</password>
</server>
<server>
<id>myserver</id>
<username>tomcat</username>
<password>tomcat</password>
</server>
</servers>
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://127.0.0.1:8080/nexus/content/groups/public/</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<properties>
<project.build.sourceEncoding>MacRoman</project.build.sourceEncoding>
<project.reporting.outputEncoding>MacRoman</project.reporting.outputEncoding>
</properties>
<!--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>
Any advice why it complains?
Review the pom.xml file inside of target/checkout/. Chances are, the pom.xml in your trunk or master branch does not have the distributionManagement tag.
I got the same message ("repository element was not specified in the POM inside distributionManagement element"). I checked /target/checkout/pom.xml and as per another answer and it really lacked <distributionManagement>.
It turned out that the problem was that <distributionManagement> was missing in pom.xml in my master branch (using git).
After cleaning up (mvn release:rollback, mvn clean, mvn release:clean, git tag -d v1.0.0) I run mvn release again and it worked.
You can also override the deployment repository on the command line:
-Darguments=-DaltDeploymentRepository=myreposid::default::http://my/url/releases
The ID of the two repos are both localSnap; that's probably not what you want and it might confuse Maven.
If that's not it: There might be more repository elements in your POM. Search the output of mvn help:effective-pom for repository to make sure the number and place of them is what you expect.
For me, this was something as simple as a missing version for my artifact - "1.1-SNAPSHOT"

JCenter - Return code is: 401, ReasonPhrase: Unauthorized

When deploying with $mvn deploy for a linked artifact into JCenter, I get this error Return code is: 401, ReasonPhrase: Unauthorized.
What is causing this, and how to fix this?
Solution is to have this in the artifact's pom.xml
<distributionManagement>
<snapshotRepository>
<id>bintray-yourusername-maven-yourpackagename</id> <!-- same id with the server in settings.xml -->
<name>oss-jfrog-artifactory-snapshots</name>
<url>http://oss.jfrog.org/artifactory/oss-snapshot-local</url>
</snapshotRepository>
</distributionManagement>
And have this in the settings.xml
<?xml version="1.0" encoding="UTF-8" ?>
<settings xsi:schemaLocation='http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd'
xmlns='http://maven.apache.org/SETTINGS/1.0.0' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
<servers>
<server>
<id>bintray-yourusername-maven-yourpackagename</id> <!-- same id with the snapshotRepository -->
<username>yourusername</username>
<password>your_api_key</password>
</server>
</servers>
<profiles>
<profile>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>bintray</name>
<url>http://jcenter.bintray.com</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>bintray-plugins</name>
<url>http://jcenter.bintray.com</url>
</pluginRepository>
</pluginRepositories>
<id>bintray</id>
</profile>
</profiles>
<activeProfiles>
<activeProfile>bintray</activeProfile>
</activeProfiles>
</settings>
Without seeing your pom file, my bet is you're trying to upload a SNAPSHOT to Bintray. Bintray is a distribution platform and intended for releases only.
You're more than welcome to use oss.jfrog.org for snapshots of packages, which are included in JCenter.

Uploading Jersey jars to local artifactory

I've been trying for almost a day now to deploy jar files from Jersey to our local Artifactory using Maven. I have made a few small changes to branch 2.6.x of Jersey and have built and packaged the jars. Here is the excerpt of parent pom from Jersey:
<groupId>org.glassfish.jersey</groupId>
<artifactId>project</artifactId>
<packaging>pom</packaging>
<version>2.6.rn-SNAPSHOT</version>
<name>jersey</name>
<description>
Jersey is the open source (under dual CDDL+GPL license) JAX-RS 2.0 (JSR 339)
production quality Reference Implementation for building RESTful Web services.
</description>
<distributionManagement>
<repository>
<id>central</id>
<name>central-repo</name>
<url>http://localhost/artifactory/libs-releases-local</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>central-repo-snapshots</name>
<url>http://localhost/artifactory/libs-snapshots-local</url>
</snapshotRepository>
</distributionManagement>
I have my settings.xml generated by artifactory and placed in ~/.m2/settings.xml
But when I try to deploy using mvn deploy, I get the following:
Uploading: (https: //maven.java.net/content/repositories/snapshots/):
Failed to transfer file: https://maven.java.net/content/repositories/snapshots/org/glassfish/jersey/project/2.6.rn-SNAPSHOT/project-2.6.rn-20150218.212627-1.pom.
Return code is: 401, ReasonPhrase: Unauthorized.
My complete settings.xml looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<servers>
<server>
<username>admin</username>
<password>admin</password>
<id>central</id>
</server>
<server>
<username>admin</username>
<password>admin</password>
<id>snapshots</id>
</server>
</servers>
<profiles>
<profile>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>libs-releases</name>
<url>http://localhost/artifactory/libs-releases</url>
</repository>
<repository>
<snapshots />
<id>snapshots</id>
<name>libs-snapshots</name>
<url>http://localhost/artifactory/libs-snapshots</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>plugins-releases</name>
<url>http://localhost/artifactory/plugins-releases</url>
</pluginRepository>
<pluginRepository>
<snapshots />
<id>snapshots</id>
<name>plugins-snapshots</name>
<url>http://localhost/artifactory/plugins-snapshots</url>
</pluginRepository>
</pluginRepositories>
<id>artifactory</id>
</profile>
</profiles>
<activeProfiles>
<activeProfile>artifactory</activeProfile>
</activeProfiles>
</settings>
You must add the distributionManagement tag in your pom.xml, where the url will be your Artifactory's url and add the credentials in settings.xml
You can read more about this here.

Categories