Issue publishing Maven package to GitHub packages - maven

How do I create a GitHub workflow that publishes a Maven artifact to GitHub Packages? I'm a bit lost, since I'm using the workflow file provided by GitHub, and Googling the issue doesn't come up with any fixes that apply to my situation.
This what I've gotten so far:
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
[...]
<distributionManagement>
<repository>
<id>github</id>
<name>GitHub Milan Dierick Maven Apache Packages</name>
<url>https://maven.pkg.github.com/MilanDierick/SongsOfSyx</url>
</repository>
</distributionManagement>
[...]
</project>
name: Maven Package
on:
workflow_dispatch:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout#v3
- name: Set up JDK 8
uses: actions/setup-java#v3
with:
java-version: '8'
distribution: 'corretto'
cache: maven
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file
- name: Build with Maven
run: mvn package
- name: Publish to GitHub Packages Apache Maven
run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml
env:
GITHUB_TOKEN: ${{ github.token }}
This is the exception I'm getting when running this workflow:
Error: Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project UnofficalSongsOfSyx: Failed to deploy artifacts: Could not transfer artifact github.gsos:UnofficalSongsOfSyx:jar:0.63.45 from/to github (https://maven.pkg.github.com/MilanDierick/SongsOfSyx): transfer failed for https://maven.pkg.github.com/MilanDierick/SongsOfSyx/github/gsos/UnofficalSongsOfSyx/0.63.45/UnofficalSongsOfSyx-0.63.45.jar, status: 422 Unprocessable Entity -> [Help 1]
Error:
Error: To see the full stack trace of the errors, re-run Maven with the -e switch.
Error: Re-run Maven using the -X switch to enable full debug logging.
Error:
Error: For more information about the errors and possible solutions, please read the following articles:
Error: [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Error: Process completed with exit code 1.

Apparently the artifact ID needs to be all lowercase. Derp.

Related

Deploying Maven project via GitHub actions fails

I'm trying to deploy a multi module project to GitHub packages but whenever Maven hits the "deploy" cycle it fails.
my GitHub action job:
release:
name: Release 🚀
# needs: test
runs-on: ubuntu-latest
permissions:
contents: write
actions: write
repository-projects: write
packages: write
steps:
- uses: actions/checkout#v3
with:
ref: master
- uses: actions/setup-java#v3
with:
java-version: 17
distribution: adopt
cache: maven
- name: Release package
run: |
git config user.name "githubaction[bot]"
git config user.email "actions#github.com"
mvn -B release:prepare
mvn -B release:perform
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
My pom files has the needed config:
<distributionManagement>
<!-- Github distribution -->
<repository>
<id>github</id>
<name>GitHub Packages</name>
<url>https://maven.pkg.github.com/MYUSERNAME/${project.artifactId}</url>
</repository>
</distributionManagement>
<scm>
<developerConnection>scm:git:https://github.com/MYUSERNAME/${project.artifactId}</developerConnection>
</scm>
The prepare step goes fine but a soon as Maven tries to perform the release (and thus hits the deploy stage) I get the error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project my-artifact-sub-module: Failed to deploy artifacts: Could not find artifact my-artifact-sub-module:jar:1.1.0 in github (https://maven.pkg.github.com/mathiasbosman/fs-core) -> [Help 1]
Which is bizar as right before it fails Maven logs:
[INFO] Uploading to github: https://maven.pkg.github.com/my/path/my-artifact-sub-module/1.1.0/my-artifact-sub-module-1.1.0.jar
[INFO] Uploading to github: https://maven.pkg.github.com/my/path/my-artifact-sub-module/1.1.0/my-artifact-sub-module-1.1.0.pom
The structure would be:
my-artifact (pom)
- my-artifact-sub-module (jar)
- my-artifact-sub-module-two (jar)
I tried calling mvn deploy manually in a seperate step but it gives me the same result.
The scm url apperently was wrong (missing the .git extension)
As simple as that.
The complete scm:
<scm>
<connection>scm:git:${project.scm.url}</connection>
<developerConnection>scm:git:${project.scm.url}</developerConnection>
<url>https://github.com/MYUSERNAME/${project.artifactId}.git</url>
<tag>HEAD</tag>
</scm>

Github Action for mvn deploy parent pom fails

I am trying to create a parent/central pom which I plan to use across all my project implementations as a common point for version management of all dependencies.
To make this central dependency pom available to other projects, I want to create a git package so that other projects can import this central dependency pom from git package.
Currently while running github action to publish package, I get the following error.
Error: Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project central-java-dependency: Failed to deploy artifacts: Could not find artifact com.dishant:central-java-dependency:pom:1.0.0 in github (https://maven.pkg.github.com/dishantkamble) -> [Help 1]
Error:
Error: To see the full stack trace of the errors, re-run Maven with the -e switch.
Error: Re-run Maven using the -X switch to enable full debug logging.
Error:
Error: For more information about the errors and possible solutions, please read the following articles:
Error: [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Error: Process completed with exit code 1.
Below is my action yml
name: Java CI with Maven
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Set up JDK 11
uses: actions/setup-java#v1
with:
java-version: 11
- name: Build with Maven
run: mvn -B package --file pom.xml
- name: Publish to GitHub Packages Apache Maven
run: mvn deploy
env:
GITHUB_TOKEN: ${{ github.token }}
My pom contains distributionManagement as follows
<distributionManagement>
<repository>
<id>github</id>
<name>GitHub Dishant Apache Maven Packages</name>
<url>https://maven.pkg.github.com/dishantkamble</url>
</repository>
</distributionManagement>
Can someone help to get this central dependency pom deployed to github packages so that my other projects can successfully import this pom as parent dependency.
I was able to fix this with the following two changes.
maven.yml
name: Java CI with Maven
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Set up JDK 11
uses: actions/setup-java#v1
with:
java-version: 11
- name: Build with Maven
run: mvn -B package --file pom.xml install
- name: Publish to GitHub Packages Apache Maven
run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml -DskipTests
env:
GITHUB_TOKEN: ${{ github.token }}
pom.xml
update existing distribution management with the repository name
<distributionManagement>
<repository>
<id>github</id>
<name>GitHub Dishant Apache Maven Packages</name>
<url>https://maven.pkg.github.com/dishantkamble/central-java-dependency</url>
</repository>
</distributionManagement>

MVN release fails with "Repository does not allow updating assets: releases" when it should not

We have a multi module project for which we want to do a release using the following command
mvn release:prepare release:perform -B -e -X
which fails with
07:54:12 [INFO] Caused by: org.eclipse.aether.transfer.ArtifactTransferException:
Could not transfer artifact ch.test.sub:my-app:pom:2019.02.07 from/to
release-repo (https://nexus.intra/content/repositories/releases/):
Failed to transfer file:
https://nexus.intra/content/repositories/releases/ch/test/sub/my-app/2019.02.07/my-app-2019.02.07.pom.
The return code is 400, ReasonPhrase: Repository does not allow updating assets: releases.
The message is pretty clear but there are some things which do not add up
When initiating maven the my-app-2019.02.07.pom is not in nexus
I examined the log and there is only one "Uploading to release-repo" happening which is when the build process fails with the message above
07:54:11 [INFO] [INFO] Uploading to release-repo:
https://nexus.intra/content/repositories/releases/ch/test/sub/my-
app/2019.02.07/my-app-2019.02.07.pom
At this point, I can observe that there is a my-app-2019.02.07.pom in the Nexus repository
How does it get there when - according to the log - there was no upload happening?
pom.xml before maven is initiated
...
<parent>
<groupId>ch.test</groupId>
<artifactId>my.app</artifactId>
<version>2019.02.07-SNAPSHOT</version>
<relativePath>../pom-parent</relativePath>
</parent>
...
Version Info
Apache Maven 3.5.4
Java version: 1.8.0_201
OS name: "windows server 2016", version: "10.0", arch: "amd64", family: "windows"
I hit this issue and resolved by manually deleting the uploaded pom file, in my case it hit issues after the pom upload, causing the release to fail. Subsequent attempts at mvn release:perform then failed as that pom already existed.
Another approach to fixing this is documented here Gradle Upload Fails But Still Deploys to Nexus

Bitbucket Pipelines - Cannot find symbol: class UniversalDetector

I tried to import juniversalcharset package on pom.xml
<dependency>
<groupId>com.googlecode.juniversalchardet</groupId>
<artifactId>juniversalchardet</artifactId>
<version>1.0.3</version>
</dependency>
Here is my bitbucket-pipelines.yml
image: maven:3.3.3
pipelines:
default:
- step:
caches:
- maven
script:
- mvn clean install -Dmaven.wagon.http.ssl.allowall=true -Dmaven.wagon.http.ssl.insecure=true
It downloads and builds correctly on my local machine, but on pipelines it displays the following error:
[ERROR] /opt/atlassian/pipelines/agent/build/src/main/java/package/location/GuessedEncoding.java:[18,15] cannot find symbol
symbol: class UniversalDetector
My guess is that it cannot find the maven artifact when building on pipelines. Is there something wrong with my pipeline configuration?
I found the solution. I forgot to commit and push pom.xml which is why pipelines failed to find the new packages.

How to deploy a 3rd party set of libs to Nexus

I want to deploy a 3rd party set of libraries to nexus after building them from the source using maven.
I thought I'd be able to simply use mvn deploy but I get the following message:
[INFO] --- maven-deploy-plugin:2.7:deploy (default-deploy) # dcm4che-parent ---
Uploading: scp://www.dcm4che.org:443/home/maven2/org/dcm4che/dcm4che-parent/3.3.7/dcm4che-parent-3.3.7.pom
The authenticity of host 'www.dcm4che.org' can't be established.
RSA key fingerprint is 41:7f:10:be:8d:15:30:f1:91:59:95:c7:5d:63:f7:31.
Are you sure you want to continue connecting? (yes/no): yes
Password: :
This looks to me like it's trying to deploy to the www.dcm4che.org and not my nexus repo.
Can I not use mvn deploy in this way?
I can deploy my own libs to nexus this way without any problems.
What am I doing wrong?
UPDATE
After following the advice in this answer I executed the following command:
mvn deploy -DaltDeploymentRepository=nexus::default::http://192.168.50.200:8081/nexus/content/repositories/thirdparty
and I get the following error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project dcm4che-parent: Failed to deploy artifacts: Could not transfer artifact org.dcm4che:dcm4che-parent:pom:3.3.7 from/to nexus (http://192.168.50.200:8081/nexus/content/repositories/thirdparty): Failed to transfer file: http://192.168.50.200:8081/nexus/content/repositories/thirdparty/org/dcm4che/dcm4che-parent/3.3.7/dcm4che-parent-3.3.7.pom. Return code is: 401, ReasonPhrase: Unauthorized. -> [Help 1]
I have added an entry in my settings.xml as follows:
<servers>
<server>
<id>thirdparty</id>
<username>deployment</username>
<password>password</password>
<configuration></configuration>
</server>
</servers>
2nd UPDATE
I have tried the following command line variations but still can't get it to work. The maven documentation isn't any help.
mvn deploy -DaltDeploymentRepository=thirdparty::default::http://192.168.50.200:8081
produces the error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project dcm4che-parent: Failed to deploy artifacts: Could not find artifact org.dcm4che:dcm4che-parent:pom:3.3.7 in thirdparty (http://192.168.50.200:8081) -> [Help 1]
and
mvn deploy -DaltDeploymentRepository=thirdparty::default::http://192.168.50.200:8081/nexus/
produces the error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project dcm4che-parent: Failed to deploy artifacts: Could not transfer artifact org.dcm4che:dcm4che-parent:pom:3.3.7 from/to thirdparty (http://192.168.50.200:8081/nexus/): Failed to transfer file: http://192.168.50.200:8081/nexus/org/dcm4che/dcm4che-parent/3.3.7/dcm4che-parent-3.3.7.pom. Return code is: 405, ReasonPhrase: HTTP method PUT is not supported by this URL. -> [Help 1]
and
mvn deploy -DaltDeploymentRepository=nexus::default::http://192.168.50.200:8081/nexus/content/repositories/
produces the error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project dcm4che-parent: Failed to deploy artifacts: Could not find artifact org.dcm4che:dcm4che-parent:pom:3.3.7 in nexus (http://192.168.50.200:8081/nexus/content/repositories/) -> [Help 1]
Final UPDATE
For anyone else who might stumble across this, the following command worked. Thanks to A_Di-Matteo for his help.
mvn deploy -DaltDeploymentRepository=thirdparty::default::http://192.168.50.200:8081/nexus/content/repositories/thirdparty
You are probably refering to the dcm4che-parent-3.3.7.pom artifact, from which:
<distributionManagement>
<repository>
<id>www.dcm4che.org</id>
<name>dcm4che Repository</name>
<url>scp://www.dcm4che.org:443/home/maven2</url>
</repository>
</distributionManagement>
As you can see, its distributionManagement is refering to the host mentioned in the build error, which is used as the default one.
If you want to deploy to your internal Nexus, you should then use the altDeploymentRepository option:
Specifies an alternative repository to which the project artifacts should be deployed (other than those specified in <distributionManagement>).
Format: id::layout::url.
Its user property is altDeploymentRepository.
Hence, you can invoke Maven as following:
mvn clean deploy -DaltDeploymentRepository=yourId::layout::URL
Which should match a repository specified in your Maven settings.xml.
As a general rule, you should not upload to Nexus public artifacts in this way: Nexus can retrieve them for you and be used as a further centralized cache/governance point for other remote repositories.
If you are changing public artifacts and then publishing them in your internal Nexus, then it is really adviced to change their Maven coordinates, at least adding a classifier specifying something related to your patch/company-name/useful-detail.

Resources