Skip to content

Commit

Permalink
Merge pull request #1 from aboutbits/ab-291-extract-checkstyle-config…
Browse files Browse the repository at this point in the history
…-in-its-own-package

Ab 291 extract checkstyle config in its own package
  • Loading branch information
SirCotare authored Oct 1, 2024
2 parents 065e7a2 + 9901124 commit fb52280
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 21 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/maven-settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<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
http://maven.apache.org/xsd/settings-1.0.0.xsd">

<activeProfiles>
<activeProfile>github</activeProfile>
</activeProfiles>

<profiles>
<profile>
<id>github</id>
<repositories>
<repository>
<id>central</id>
<url>https://repo1.maven.org/maven2</url>
</repository>
<repository>
<id>github</id>
<url>https://maven.pkg.github.com/aboutbits/*</url>
</repository>
</repositories>
</profile>
</profiles>

<servers>
<server>
<id>github</id>
<username>${env.GITHUB_USER_NAME}</username>
<password>${env.GITHUB_ACCESS_TOKEN}</password>
</server>
</servers>
</settings>
44 changes: 44 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Publish package to GitHub Packages
on:
workflow_dispatch:
inputs:
version:
description: "Version name to publish (eg: x.x.x)"
type: string
required: true

jobs:
publish:
timeout-minutes: 15
runs-on: ubuntu-22.04
permissions:
contents: read
packages: write

steps:
- uses: actions/checkout@v4

- uses: aboutbits/github-actions-java/setup@v3

- name: Set Version
run: sed -i 's|<version>BUILD-SNAPSHOT</version>|<version>${{ github.event.inputs.version }}</version>|g' pom.xml

- name: Publish package
run: mvn -s $GITHUB_WORKSPACE/.github/workflows/maven-settings.xml --batch-mode deploy
env:
GITHUB_USER_NAME: ${{ github.actor }}
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}

tag:
timeout-minutes: 5
runs-on: ubuntu-22.04
needs: publish
steps:
- uses: actions/checkout@v4

- name: Tag Deployment
uses: aboutbits/github-actions-base/git-create-or-update-tag@v1
with:
tag-name: ${{ github.event.inputs.version }}
user-name: 'AboutBits'
user-email: '[email protected]'
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea
.idea
target
19 changes: 19 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?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>

<groupId>it.aboutbits</groupId>
<artifactId>java-checkstyle-config</artifactId>
<version>BUILD-SNAPSHOT</version>
<description>Checkstyle config for all JAVA projects.</description>
<packaging>jar</packaging>

<distributionManagement>
<repository>
<id>github</id>
<name>GitHub Packages</name>
<url>https://maven.pkg.github.com/aboutbits/java-checkstyle-config</url>
</repository>
</distributionManagement>
</project>
31 changes: 11 additions & 20 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,15 @@ Checkstyle config for all JAVA projects.

## Usage

Add this repository as a submodule of your main project by creating a `.gitmodules` file:
```
[submodule "checkstyle-config"]
path = checkstyle-config
url = https://github.com/aboutbits/java-checkstyle-config
branch = main
```

Add the `maven-checkstyle-plugin` to your `pom.xml`:
```xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.5.0</version>
<configuration>
<configLocation>checkstyle-config/checkstyle.xml</configLocation>
<suppressionsLocation>checkstyle-config/checkstyle-suppressions.xml</suppressionsLocation>
<configLocation>checkstyle.xml</configLocation>
<suppressionsLocation>checkstyle-suppressions.xml</suppressionsLocation>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
Expand All @@ -41,21 +33,20 @@ Add the `maven-checkstyle-plugin` to your `pom.xml`:
<artifactId>checkstyle</artifactId>
<version>10.18.1</version>
</dependency>
<dependency>
<groupId>it.aboutbits</groupId>
<artifactId>java-checkstyle-config</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</plugin>
```

For use with github-actions, you will also have to tell `actions/checkout` to also recurse submodules:
```yaml
- uses: actions/checkout@v4
with:
submodules: 'true'
```
**Configure your IDE:**
Go to `Settings` then search for "checkstyle".
Add a new checkstyle configuration and select the `checkstyle-config/checkstyle.xml` file.
Set the property `org.checkstyle.sun.suppressionfilter.config` to `checkstyle-config/checkstyle-suppressions.xml`
First you need to run `mvn verify` once.
In your IDE go to `Settings` then search for "checkstyle".
Add a new checkstyle configuration and select the `target/checkstyle-checker.xml` file.
Set the property `org.checkstyle.sun.suppressionfilter.config` to `checkstyle-suppressions.xml`

## Information

Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit fb52280

Please sign in to comment.