All jobs

Fix "Source option 5 is no longer supported. Use 7 or later." in Maven

Yes. An agent finds where the POM pins Java 5, raises the compiler level to one your JDK accepts, runs the build and tests, and opens a PR with the output.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent reproduces the error first, with the JDK and Maven versions printed beside it, because the message depends on both. In a library like tdebatty/java-LSH, mvn compile on a JDK 17 stops in maven-compiler-plugin:2.3.2:compile with two lines: Source option 5 is no longer supported. Use 7 or later. and the same sentence for Target option 5. The number at the end is the oldest language level that particular JDK still compiles, so a colleague on a different JDK may see a different floor in the otherwise identical message.

It then finds where the 5 comes from. There are two usual sources. One is an explicit setting, and that is the case here: pom.xml configures the compiler plugin with <source>1.5</source> and <target>1.5</target>. The other is no setting at all, where an old compiler plugin falls back to its built-in default. The agent checks the effective POM, including any parent, and reports which case applies, since the second one is fixed by adding configuration and the first by changing it.

Choosing the new level is the part that needs reading. The agent looks at what the code uses and what the project promises: the .travis.yml, the README and, for a published artifact, who consumes it. This POM publishes info.debatty:java-lsh through Sonatype, so the bytecode level is part of the library's interface. It proposes Java 8 as a level every JDK in current use can still target, sets 1.8 in both elements, and leaves the plugin version alone in the first commit so the diff shows one change. As a second, optional commit it offers the tidier form: a newer compiler plugin and the single maven.compiler.release property, which also checks API use against that release and needs JDK 9 or later to build.

Then it runs what the project's own lifecycle runs. mvn -B test compiles, runs the three JUnit classes under src/test/java, and executes the checkstyle check that the POM binds to the test phase with failsOnError. The agent does not run verify or deploy unmodified: the POM binds maven-gpg-plugin to verify, which needs a signing key the sandbox does not have. It follows the Travis install line and passes -Dgpg.skip=true where a later phase is needed.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "The Maven build fails with: Source option 5 is no longer supported. Use 7 or later. (and the same for Target option 5). Fix it. Print java -version and mvn -version, run the failing goal and quote the error. Find where the source and target levels come from: explicit maven-compiler-plugin configuration, maven.compiler.source/target/release properties, a parent POM, or the plugin's built-in default; use mvn help:effective-pom if it is not obvious, and say which it is. Decide the new level from evidence: what language features the code uses, what CI builds on, what the README promises, and, if the artifact is published, that consumers on older runtimes will be affected. Propose the lowest level that the installed JDK and current LTS JDKs can all compile, state it, and apply it to both source and target. Make that the first commit, changing nothing else. Then run the build through the test phase and quote the test and static-analysis results; if a later phase needs signing keys or deploy credentials, skip those plugins with their documented flags and say so, and never run deploy. In a second commit, only if the first build is green, replace source and target with a single maven.compiler.release property and upgrade maven-compiler-plugin to a version that supports it; rerun the build and report any new warnings or errors. Update CI configuration and README statements about the Java version to match. Open a pull request that states the old and new bytecode level in its first line.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

A pull request whose first commit changes two lines of pom.xml. The description opens with the old and new level, then the reproduced error with the JDK version that produced it, then the build output after the change: the compiler step, the test summary and the checkstyle result. Because the build was red before and should be green after with a two-line diff, the reviewer can match cause and effect without running anything.

The second commit, when present, is the modernisation: the plugin version and the release property. It is kept separate because it can surface things the first does not, such as deprecation warnings from a much newer compiler plugin or an API that does not exist in the chosen release. A reviewer who only wants the build fixed can take the first commit and leave the second for later.

For a library, the reviewer also reads the compatibility note. Raising the target from 5 to 8 means the published jar no longer loads on Java 5, 6 or 7 runtimes. That is rarely a real loss, and it is still a change in what the artifact promises, so the description says it in one sentence and suggests the version bump and changelog line that go with it.

Run it on every failed build after a JDK upgrade

This error tends to arrive in batches: a CI image moves to a newer JDK and every repository with an old POM fails on its next build. In each repository's Project, an automation with a github trigger on check_suite.failure or workflow_run.failure starts a run when CI fails, with the failure event placed after the saved prompt. The trigger does not filter on the error text, so the prompt should tell the agent to read the failing job's log and end with a one-line note when the cause is something other than a source or target level.

Pull requests and CI runs from forks never fire the trigger, and neither do bot senders, so a dependency bot's failing branch will not start a run. Set the automation's max runs per hour to a number of pull requests you would be willing to review in that hour; events past it wait for room.

The use case this job follows, with its automation and trigger: Fix a bug from an alert.

Why run it on Rush?

The edit is two lines and the reason to hand it off is everything around those lines. Reproducing the error needs the newer JDK, confirming the fix needs a full build with tests and static analysis, and a careful answer checks more than one JDK. The run installs the JDK and Maven it needs in its own sandbox, downloads the project's plugins and dependencies there, and keeps the build output in the transcript. Nobody has to switch JAVA_HOME on a laptop or wait for a cold local repository to fill.

It also handles the batch. After a JDK upgrade the same failure appears in many repositories on the same day, each with a slightly different POM: an explicit 1.5 in one, a parent POM in another, no compiler configuration in a third. One run per repository works through them in parallel and each returns a pull request that says which case it found, which is faster to review than a scripted search and replace that assumed they were all the same.

Frequently asked questions

Why does the message say 7 on my machine and something else on a colleague's?

The JDK prints the oldest level it still supports, and each JDK generation drops old ones. The wording in this page's title is what a JDK 17 prints. Other JDK versions end the sentence with a different number. The fix is the same in every case: set a level the JDK you build with still accepts.

There is no source or target in my pom.xml. Where does 5 come from?

From the compiler plugin's default. Old versions of maven-compiler-plugin compiled for Java 5 when nothing was configured, and a POM that never pins the plugin version can inherit such a default. The agent prints the effective POM to show the plugin version in use, then adds an explicit level so the build no longer depends on a default.

Should I use source and target or release?

release is the better end state: one value, and the compiler also rejects calls to APIs that the chosen release does not have. It needs JDK 9 or later and a compiler plugin recent enough to pass it through. The agent applies source and target first so the fix works with the plugin you have, then offers release as a separate commit.

Will the agent publish or sign anything?

No. It runs the build through the phases that compile, test and check, and skips signing and staging plugins with their own skip flags when a later phase is needed. It has no signing key or repository credentials in its sandbox, and the prompt forbids deploy.

More Maven jobs

More jobs like this: Fix a bug from an alert

Keep reading