Github Action for mvn deploy parent pom fails - maven

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>

Related

Issue publishing Maven package to GitHub packages

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.

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>

In github actions, mvn install says that pom.xml does not exist

Here is my repository: https://github.com/klashdevelopment/klashitemsystem
I'm trying to get the GitHub action in there to work (i am brand new to GitHub actions) What I want to do in my action is: when there is a push, run mvn install and release the jar file to releases. I'm not too sure how to do this, and I tried to smash together a few other people's GitHub actions to do what I want. When I run this, however, it says that no pom.xml exists (when it does exist in the repository) I even tried setting the working directory. Anyone know why?
Error: The goal you specified requires a project to execute but there is no POM in this directory (D:\a\klashitemsystem\klashitemsystem). Please verify you invoked Maven from the correct directory. -> [Help 1]
Workflow:
steps:
- name: Set up JDK
uses: actions/setup-java#v1
with:
java-version: 17
- name: Packaging Jar
id: packaging-jar
shell: bash
run: |
cd .
mvn clean install
You need to check out your code. Add this step:
steps:
- name: Check out Repository
uses: actions/checkout#v3
- name: Set up JDK
uses: actions/setup-java#v3
with:
java-version: 17
- name: Packaging Jar
id: packaging-jar
shell: bash
run: mvn clean install

Maven build in github continuous integration action

I am using Github actions to set up a continuous integration workflow for a Maven app. The Maven app depends on some external dependencies as well as a couple other repositories that we built. In my Github action's .yaml file, I've included the line "mvn install". When I make a commit, the action begins to run the .yaml file as expected. The build mostly works, and can find external maven dependencies from maven central. However, the build cannot find the two other private repositories. These repositories are saved on the same github account as the repo. for this app.
Downloading from central: https://repo.maven.apache.org/maven2/com/<repo>/1.3/<repoName>-1.3.pom
[WARNING] The POM for com.<repo>/<reponame>.core:jar:1.3 is missing, no dependency information available
Here is my github/workflow action's yaml file...
name: Build1
on:
push:
branches:
- '*'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v1
- name: Run a one-line script
run: echo Hello, world!
- name: Run a multi-line script
run: |
echo Add other actions to build,
echo test, and deploy your project.
- name: Build
run: mvn install

How to automate versioning of Maven project in GitHub?

I am trying to make auto- or semi-auto versioning into GitHub.
I looked into the automation release workflow possibilities and it doesn't seem like anything standard for GitHub.
I want to have an automatic update of version in pom.xml whenever I create a tag on GitHub or whenever I merge into the master branch.
I found a workaround solution with Github Actions that can be extended further. Whenever I release and I manually specify release notes and changelog, so this release version can be taken from github.event.release.tag_name
mvn -B versions:set -DnewVersion=${{ github.event.release.tag_name }} -DgenerateBackupPoms=false
The reference to the actual GitHub workflow is here.
.github/workflows/deploy.yml at the time of writing:
name: Publish package to the Maven Central Repository
on:
release:
types: [created]
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Check out Git repository
uses: actions/checkout#v2
- name: Install Java and Maven
uses: actions/setup-java#v1
with:
java-version: 8
- if: github.event.release
name: Update version in pom.xml (Release only)
run: mvn -B versions:set -DnewVersion=${{ github.event.release.tag_name }} -DgenerateBackupPoms=false
- name: Release Maven package
uses: samuelmeuli/action-maven-publish#v1.4.0
with:
maven_profiles: deploy, verify
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
gpg_passphrase: ${{ secrets.GPG_PASSPHRASE }}
nexus_username: ${{ secrets.OSSRH_USERNAME }}
nexus_password: ${{ secrets.OSSRH_TOKEN }}

Resources