Github Workflow Maven Caching - Multi-Module Project - maven

I am working on integrating Sonar for a multi-module Maven Project which has 3 modules. I need to speed up the Maven Build Process by enabling caching. Sonar Reports are working correctly but still the caching is not happening. Below here find the Github Workflow File with the configurations which I want to cache the dependencies only relevant to the cloud-pci-ui module
Module Structure
Maven Caching Error
name: Analyze pull request
on:
# Trigger analysis when open edit, synchronize or re-opene a pull request.
pull_request:
types: [opened, edited, synchronize, reopened]
env:
# Sets environment variable
AWS_REGION : us-east-1
jobs:
buildAndAnalysePR:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
with:
# Disabling shallow clone is recommended for improving relevancy of reporting
fetch-depth: 0
- uses: actions/setup-java#v2
with:
distribution: 'adopt'
java-version: '8'
cache: 'maven'
- name: Cache local Maven repository
uses: actions/cache#v2
with:
path: ~/cloud-pci-ui/.m2/repository/
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
- name: Build PCI-API
run: |
cd cloud-pci-api
mvn clean install -DskipTests

Related

Gitlab CI/CD with gradle build and push to Google Artifactory Registry GCP AR

I'm building a pipeline in GitLab CI/CD with the .gitlab-ci.yml file. It's a Java application, gradle is the build too and I have to push this artifact to GCP AR.
So I'm using a gradle image and I don't know where after the build my artifact is located and the syntax I'll use to push that artifact to Google Artifact.
Below is my progress:
image: gradle:alpine
stages:
- build
- test
Build_Stage:
stage: build
script:
- gradle build
cache:
paths:
- build
- .gradle
Test_Job:
stage: test
script:
- gradle check
cache:
paths:
- build
- .gradle
after_script:
- echo "End of CI"
console output on GitLab I don't even know if it actually build a .jar and where the .jar package is at

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

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

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