AGENT SKILL

maven-build-lifecycle

Use when reproducing and repairing Maven CI build failures, especially legacy multi-module builds and Maven Invoker integration tests.

License 许可
Apache-2.0
最近更新
2026-11-14
Stars
★ 0
Forks
1

01 前言 Front Matter

name
maven-build-lifecycle
description
Use when reproducing and repairing Maven CI build failures, especially legacy multi-module builds and Maven Invoker integration tests.

03 SKILL.md 正文

Steps

  1. Locate the real checkout workspace under /home/travis/build/failed/** (do not stop at a namespace/owner folder; you must reach the final build workspace that contains pom.xml and usually a .git directory/file).

    • Start with discovery (single tool calls; a short cd ... && ls -la is OK):
      cd /home/travis/build/failed && ls -la
      
    • Drill down with ls -la until you reach the directory that actually contains the build files.
    • If you’re unsure where the checkout root is, find it directly:
      find /home/travis/build/failed -maxdepth 5 -type d -name .git -print
      
      Then cd to the parent directory of the .git hit and confirm:
      pwd
      
      ls -la
      
      (You should see pom.xml, .travis.yml, mvnw, or module directories.)
  2. Read CI configuration before interpreting errors to learn the real Maven command and JDK:

    sed -n '1,220p' .travis.yml
    
  3. Record toolchain versions (paste these into failed_reasons.txt):

    java -version
    
    javac -version
    
    mvn -version
    
  4. Match the CI JDK before patching project files. If CI pins an older JDK and the environment provides the BugSwarm/Travis switcher:

    source /opt/jdk_switcher/jdk_switcher.sh
    
    jdk_switcher use <ci-jdk>
    
    export TRAVIS_JDK_VERSION=<ci-jdk>
    
    java -version
    

    Do not “modernize away” failures that only occur because you ran the project on a newer JDK than CI.

  5. Reproduce the failure using the CI command (same flags/profiles, including any -f <reactor-pom>). If you need clearer “missing artifact/plugin” coordinates, also try:

    mvn -o -B -e verify --fail-at-end
    
  6. Write/update the required diagnosis + plan file early (don’t defer; keep updating as you learn more):

    printf '%s\n' \
      "Repo: $(pwd)" \
      "Repro command: <paste exact mvn command from CI>" \
      "Observed failure: <paste key Maven error lines>" \
      "Root cause guess: <code vs build config?>" \
      "Plan: <files to change + why>" \
      > /home/travis/build/failed/failed_reasons.txt
    

    Verify it exists and is non-empty:

    test -s /home/travis/build/failed/failed_reasons.txt && echo "notes ok"
    
  7. Maven Invoker / nested test projects: fix dependency resolution in the template sources, not target/**.

    • If the failure is in a nested build (Invoker often runs under target/it/** or target/**), map the failing nested directory back to its source template (commonly src/it/**, sometimes src/test/resources/**) and edit that template’s pom.xml / invoker.properties, not generated copies under target/**.
    • Choose the correct modification scope by checking the nested project’s <parent> chain:
      • If the nested project does not inherit from your reactor/parent POM, fixes must be made inside the nested template (or a parent POM within that template), because it won’t see your reactor dependencyManagement/pluginManagement.
      • If it does inherit from a repository parent POM, fix the parent so the nested project picks up the change naturally.
    • Distinguish plugin resolution failures vs normal dependency failures; nested builds may need their own plugin versions/repositories when they don’t inherit yours.
  8. Create the required patch diff file(s), then apply them to the repo.

    • Generate a unified diff from local edits (run in the repo root so the patch lands at /home/travis/build/failed/<repo>/<id>/patch_1.diff):
      git diff > patch_1.diff
      
      test -s patch_1.diff && echo "patch ok"
      
    • Prove/apply the patch artifact (separates “patch creation” from “patch application”):
      git checkout -- .
      
      git apply patch_1.diff
      
    • Verify the working tree reflects the patch:
      git status
      
      git diff --stat
      
  9. Re-run the exact CI verification command until it succeeds, remembering mvn verify may run integration/Invoker steps that mvn test does not.

Expected Result

  • You are working inside the concrete checkout directory (contains pom.xml and typically .git).
  • /home/travis/build/failed/failed_reasons.txt exists and is non-empty.
  • patch_1.diff exists in the repo root and is non-empty.
  • The Maven CI command (including nested/Invoker builds when present) passes under the CI-declared JDK.

04 同仓库更多 Skills