Deploying Maven project via GitHub actions fails - maven

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>

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.

azure pipeline maven release

I am writing my first pipeline and if some one can please help. I have issue with creating a release version jar.
2 pom.xml (1 in master branch and 1 in development branch )
master branch pom.xml has release plugin defined
development branch pom.xml has compile and release plugin defined .
apart from that both pom.xml is same
When i run the pipeline from development branch it checkout development pom.xml and working absolutely fine like create snapshot.jar , (i use mvn clean install here )
When i run the pipeline from master branch it checkout master pom.xml and giving parent pom not solvable issue , (i use mvn release:prepare release:perform here )
[Thread-5] INFO org.apache.maven.shared.release.exec.InvokerMavenExecutor - [FATAL] Non-resolvable parent POM for com.xxxxxxxxx: com.xxxxx-parent:pom:1.0.0 was not found in https://repo.maven.apache.org/maven2 during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of central has elapsed or updates are forced and 'parent.relativePath' points at wrong local POM # line 5, column 13
[Thread-5] INFO org.apache.maven.shared.release.exec.InvokerMavenExecutor - # ```
the strange part is when i use mvn clean install like in development in master branch code , it gives no problem but it is releasing snapshot.jar .
My release plugin has some issue , i dont know what
my goal is when running from development branch it should create snapshot.jar and when i run from master branch it should create <application>_release_version.jar .
any help much appreciated
- task: ArtifactoryMaven#2
inputs:
# mavenPomFile: '${{ parameters.layer }}/pom.xml'
# goals: 'clean install'
mavenPomFile: 'pom_azure.xml'
goals: 'release:prepare release:perform'
# options: '-U -DlocalCheckout=true -Dresume=false --batch-mode -Dtag=v1.0.0 -DreleaseVersion=1.0.0 -DdevelopmentVersion=2.0.0-SNAPSHOT Dusername=Personal%20Access%20Token -Dpassword=11c9decb81845396ecbd4bc8f09521e73077bbbf'
options: '-B -DpushChanges=false -DlocalCheckout=true -Dresume=false --batch-mode -DreleaseVersion=${{ parameters.release_ver }} -DdevelopmentVersion=${{ parameters.release_ver }}-SNAPSHOT'
artifactoryResolverService: 'xxxx'
targetResolveReleaseRepo: 'aaa-maven-virtual'
targetResolveSnapshotRepo: 'aaa-maven-virtual'
artifactoryDeployService: 'xxxx'
targetDeployReleaseRepo: 'aaa-main-maven-releases'
targetDeploySnapshotRepo: 'bbb-main-maven-snapshots'
collectBuildInfo: true
buildName: '$(Build.DefinitionName)'
buildNumber: '$(Build.BuildNumber)'
displayName: 'Maven Release'

Gitlab Runner download the maven dependency For each build , Don't get from cache!=

I configurd the .gitlab-ci.yml, it is a java project and needs to maven repository, my local repository is nexus, I downloading the dependency from nexux successfully , but For each build it still downloads all the dependencies every time from nexus and it don't caching.
.gitlab-ci.yml configuration is :
image: nexus.local.ir:8095/maven:3.6.3-jdk-8
######## run image #########
stages:
- build
cache:
key: maven-cache
paths:
- .m2/repository
######### cache ############
build:
stage: build
script:
- mvn package -s config/settings.xml -Dmaven.test.skip=true

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>

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

Resources