diff --git a/.github/workflows/build-jdk17.yml b/.github/workflows/build-jdk17.yml index a924cbd..aa2b6eb 100644 --- a/.github/workflows/build-jdk17.yml +++ b/.github/workflows/build-jdk17.yml @@ -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 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d8ee1b4..35a8bbf 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 diff --git a/.github/workflows/dependency-submission.yml b/.github/workflows/dependency-submission.yml new file mode 100644 index 0000000..06176be --- /dev/null +++ b/.github/workflows/dependency-submission.yml @@ -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 diff --git a/.github/workflows/tag_release.yml b/.github/workflows/tag_release.yml index f6d1106..393d5c5 100644 --- a/.github/workflows/tag_release.yml +++ b/.github/workflows/tag_release.yml @@ -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 diff --git a/.gitignore b/.gitignore index 3b72462..cecf595 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ !.gitattributes !.github/ !.default.docker.env +!.mvn/ # Ignore generated files target diff --git a/CHANGELOG.md b/CHANGELOG.md index e3dfb7b..9d3701f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index aeeae91..01303d8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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. diff --git a/TECH_DEBT.md b/TECH_DEBT.md new file mode 100644 index 0000000..123cd6b --- /dev/null +++ b/TECH_DEBT.md @@ -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). diff --git a/pom.xml b/pom.xml index dca9247..4d2e810 100644 --- a/pom.xml +++ b/pom.xml @@ -439,6 +439,18 @@ verify + + + org.sonarsource.python:sonar-python-plugin + ${test-it.sonarqube.keepRunning} ${test-it.orchestrator.artifactory.url} diff --git a/src/it/test-projects/creedengo-python-plugin-test-project/.mvn/maven.config b/src/it/test-projects/creedengo-python-plugin-test-project/.mvn/maven.config new file mode 100644 index 0000000..a098efc --- /dev/null +++ b/src/it/test-projects/creedengo-python-plugin-test-project/.mvn/maven.config @@ -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.