Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/build-jdk17.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ jobs:
java-version: 17
cache: maven

# Maven 3.10 no longer provides maven-shared-utils, required by
# maven-git-versioning-extension 9.12.1 (MessageUtils).
# Integration tests invoke "mvn" directly: use the exact wrapper distribution.
# Remove once the extension supports Maven 3.10 (TECH_DEBT.md, TD-1).
- name: Use wrapper Maven for integration tests
run: |
MVN_HOME="$(./mvnw -B -v | sed -n 's/^Maven home: //p')"
test -x "$MVN_HOME/bin/mvn"
echo "$MVN_HOME/bin" >> "$GITHUB_PATH"

- name: Check Maven version
run: mvn -v

# required so the "sonar:sonar" prefix resolves during the integration
# tests (maven-failsafe-plugin), which analyze a test project via Sonar
- name: Configure Maven for Sonar
Expand Down
13 changes: 13 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ jobs:
java-version: 21
cache: maven # enable maven cache shared by all github actions builds

# Maven 3.10 no longer provides maven-shared-utils, required by
# maven-git-versioning-extension 9.12.1 (MessageUtils).
# Integration tests invoke "mvn" directly: use the exact wrapper distribution.
# Remove once the extension supports Maven 3.10 (TECH_DEBT.md, TD-1).
- name: Use wrapper Maven for integration tests
run: |
MVN_HOME="$(./mvnw -B -v | sed -n 's/^Maven home: //p')"
test -x "$MVN_HOME/bin/mvn"
echo "$MVN_HOME/bin" >> "$GITHUB_PATH"

- name: Check Maven version
run: mvn -v

# to be able to use "sonar:sonar" instead of "org.sonarsource.scanner.maven:sonar-maven-plugin:sonar"
# inside this build but also when the test project analysis is launched with sonar:sonar
- name: Configure Maven for Sonar
Expand Down
46 changes: 46 additions & 0 deletions .github/workflows/dependency-submission.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Dependency Submission

on:
push:
branches:
- main
pull_request:
types: [ opened, synchronize, reopened ]
workflow_dispatch:

jobs:
dependency-submission:
name: Submit Maven dependencies
runs-on: ubuntu-latest
# Fork and Dependabot pull requests have read-only tokens.
if: github.event_name != 'pull_request' || (github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]')
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0

- name: Set up JDK
uses: actions/setup-java@de7274f081f381c8f8158605e0321c36c376e2e6 # v6.0.1
with:
distribution: 'temurin'
java-version: 21
cache: maven

# The submission action invokes "mvn", not "./mvnw".
# Maven 3.10 removed maven-shared-utils (MessageUtils), still required by
# maven-git-versioning-extension 9.12.1. Use the exact wrapper distribution
# until the extension supports Maven 3.10 (TECH_DEBT.md, TD-1).
- name: Use wrapper Maven for dependency submission
run: |
MVN_HOME="$(./mvnw -B -v | sed -n 's/^Maven home: //p')"
test -x "$MVN_HOME/bin/mvn"
echo "$MVN_HOME/bin" >> "$GITHUB_PATH"

- name: Check Maven version
run: mvn -v

- name: Submit dependencies
uses: advanced-security/maven-dependency-submission-action@b275d12641ac2d2108b2cbb7598b154ad2f2cee8 # v5.0.0
4 changes: 3 additions & 1 deletion .github/workflows/tag_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ jobs:
# the plugin maven-release-plugin uses the environment variable VERSIONING_GIT_REF to determine the version to use when building the project.
# By setting this variable to refs/tags/${{ env.release_tag }}, we are telling the plugin to use the specified tag as the project version.
VERSIONING_GIT_REF: refs/tags/${{ env.release_tag }}
run: mvn -e -B clean package -DskipTests -Drevision=${{ env.release_tag }}
# Use the pinned wrapper: runner Maven 3.10 is incompatible with the
# current versioning extension (TECH_DEBT.md, TD-1).
run: ./mvnw -e -B clean package -DskipTests -Drevision=${{ env.release_tag }}

- name: Resolve JAR filename
id: resolve_jar
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
!.gitattributes
!.github/
!.default.docker.env
!.mvn/

# Ignore generated files
target
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- [#185](https://github.com/green-code-initiative/creedengo-python/pull/185) Fix Maven CI compatibility with Maven 3.10 by using the pinned wrapper for builds and dependency submission, isolating integration-test Maven roots and the Failsafe classpath.
- upgrade internal libraries versions
- [#151](https://github.com/green-code-initiative/creedengo-python/issues/151)refacto to have all the test files in the same place (for UT and IT), to avoid maintaining 2 test directories
- [#151](https://github.com/green-code-initiative/creedengo-python/issues/151)refacto all test files to add sub-directories for each rule, to be more clear and to be able to add more tests for each rule in the future
Expand Down
21 changes: 21 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1 +1,22 @@
Please read common [CONTRIBUTING.md](https://github.com/green-code-initiative/creedengo-common/blob/main/doc/CONTRIBUTING.md) in `creedengo-common` repository.

## Maven and integration tests

Use `./mvnw` to build this repository. Integration tests also launch `mvn`
directly, so put the wrapper distribution first in `PATH` when running them locally:

```sh
MVN_HOME="$(./mvnw -B -v | sed -n 's/^Maven home: //p')"
test -x "$MVN_HOME/bin/mvn" || exit 1
export PATH="$MVN_HOME/bin:$PATH"
mvn -v
./mvnw -B verify
```

The `sonar:sonar` prefix used by integration tests must also resolve: configure
`org.sonarsource.scanner.maven` in Maven settings `pluginGroups`, as shown in
the build workflows.

See [TECH_DEBT.md](TECH_DEBT.md) for the Maven 3.10 compatibility workaround,
integration-test classpath isolation, cleanup criteria, and dependency-submission
settings required after merging the explicit workflow.
89 changes: 89 additions & 0 deletions TECH_DEBT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Technical debt

## TD-1 - Maven 3.10 and the versioning extension

### Problem and affected surfaces

The repository loads `me.qoomon:maven-git-versioning-extension:9.12.1` from
`.mvn/extensions.xml`. This extension uses
`org.apache.maven.shared.utils.logging.MessageUtils`, provided by
`maven-shared-utils`. Maven 3.10 no longer supplies that library, so loading the
extension can fail with `NoClassDefFoundError`.

The wrapper pins Maven 3.9.9 and works with this extension. Running the main
build with `./mvnw` alone is not sufficient: integration tests launch `mvn`
directly to analyze the nested test project. Without its own `.mvn` directory,
that project discovers the repository's Maven root and inherits the extension.
The runner's Maven can also be used by release builds and GitHub's automatic
dependency-submission workflow.

### Current workarounds

| Surface | Files | Workaround |
| --- | --- | --- |
| Main builds and nested Maven processes | `.github/workflows/build.yml`, `.github/workflows/build-jdk17.yml` | Resolve `Maven home` using `./mvnw -B -v`, verify `bin/mvn` exists, append that exact `bin` to `GITHUB_PATH`, then log `mvn -v`. Do not select an arbitrary cached distribution. |
| Release packaging | `.github/workflows/tag_release.yml` | Build with `./mvnw` instead of runner `mvn`. |
| Dependency submission | `.github/workflows/dependency-submission.yml` | Run an explicit workflow with the same wrapper-derived `PATH`, JDK 21 and Maven cache. Grant `contents: write` only to its job; skip fork and Dependabot pull requests with read-only tokens. |
| Independent analysis project | `src/it/test-projects/creedengo-python-plugin-test-project/.mvn/maven.config` | Comments only: the `.mvn` directory establishes a separate Maven root without adding arguments or loading the repository extension. |
| Tracking Maven configuration | `.gitignore` | Allow `.mvn` directories through the dotfile ignore rule with `!.mvn/`. |
| Local development | `CONTRIBUTING.md` | Document wrapper-derived `PATH` for integration tests and scanner prefix configuration. |

### Repository setting after integration

After merging the explicit workflow, a repository administrator must open
**Settings > Advanced Security > Dependency graph**:

- Keep **Dependency graph** enabled.
- Disable **Automatic dependency submission** to stop GitHub's generated Maven
workflow from running with an uncontrolled Maven installation.

The explicit workflow replaces automatic submission, not the dependency graph.
It runs on pushes to `main`, eligible pull requests (`opened`, `synchronize`,
`reopened`), and manual dispatch. No remote repository setting is changed by
this patch.

### Cleanup procedure

1. Upgrade the versioning extension to a release verified compatible with Maven
3.10. Check its upstream release notes rather than assuming a version fixes it.
2. Test the main build, release packaging, dependency submission, and nested test
analysis with Maven 3.10, including both JDK 17 and JDK 21 build configurations.
3. Remove the temporary wrapper-derived `PATH` steps and associated comments
once direct `mvn` invocations are proven compatible. Keeping `./mvnw` for
reproducible main/release builds is still recommended.
4. Remove the test project's comment-only `.mvn/maven.config` if root isolation
is no longer needed. Keep the generic `!.mvn/` exception in `.gitignore` for
repository Maven configuration. Recheck nested analysis after removal.
5. Decide whether to retain controlled, explicit dependency submission or restore
GitHub automatic submission. If restoring automatic submission, verify it
succeeds before removing the explicit workflow; do not keep both active.
6. Update this document and `CONTRIBUTING.md` to reflect the verified setup.

## TD-2 - Integration-test analyzer classpath isolation

This is separate from Maven 3.10 compatibility.

`org.sonarsource.python:sonar-python-plugin` is required for compilation and unit
tests, but is installed into the SonarQube server by Failsafe's `test-it.plugins`.
It is not needed in the Failsafe JVM. Its bundled classes can mask dependencies
used by `sonar-orchestrator`.

The Failsafe execution in `pom.xml` excludes only that analyzer artifact using
`classpathDependencyExcludes`. Its installation into SonarQube and the unit-test
classpath remain unchanged. `creedengo-integration-test` remains at **0.6.0**.
In particular, when upgrading to **0.7.0 or later**, check for bundled
`commons-lang3` conflicts: `ObjectUtils.getIfNull(Object, Object)` requires
`commons-lang3` 3.18 or later. This does not claim that 0.7.0 is already installed
or that the current build has that exact failure.

Keep the exclusion while the analyzer bundles conflicting classes. Reconsider
it only after inspecting the analyzer and orchestrator dependency/classloading
behavior and successfully running both unit and integration tests without it.
Do not remove it merely because the Maven versioning extension is upgraded.

## References

- Original cross-language correction: [green-code-initiative/creedengo-php#164](https://github.com/green-code-initiative/creedengo-php/pull/164).
- [Upstream Maven Git Versioning Extension](https://github.com/qoomon/maven-git-versioning-extension).
- [Runner images Maven issue](https://github.com/actions/runner-images/issues/14883).
- [Maven 3.10.0 release notes](https://maven.apache.org/docs/3.10.0/release-notes.html).
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,18 @@
<goal>verify</goal>
</goals>
<configuration>
<!--
The Python analyzer is installed in SonarQube via test-it.plugins,
not needed in the Failsafe JVM. Its bundled dependencies can mask
sonar-orchestrator dependencies, notably when upgrading to
creedengo-integration-test >= 0.7.0: commons-lang3
ObjectUtils.getIfNull(Object, Object) requires >= 3.18.
Keep unit-test dependencies unchanged. This isolation is independent
of Maven 3.10 (TECH_DEBT.md, TD-2).
-->
<classpathDependencyExcludes>
<classpathDependencyExclude>org.sonarsource.python:sonar-python-plugin</classpathDependencyExclude>
</classpathDependencyExcludes>
<systemPropertyVariables>
<test-it.sonarqube.keepRunning>${test-it.sonarqube.keepRunning}</test-it.sonarqube.keepRunning>
<test-it.orchestrator.artifactory.url>${test-it.orchestrator.artifactory.url}</test-it.orchestrator.artifactory.url>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This .mvn directory gives the test project its own Maven root.
# Do not inherit the repository's maven-git-versioning-extension: version 9.12.1
# requires MessageUtils from maven-shared-utils, removed from Maven 3.10.
# No Maven arguments are needed here. See TECH_DEBT.md, TD-1, for removal.
Loading