fix(import): give test source folders their own output directory #91

Merged
fred merged 1 commit from fix/84-test-output-folder into main 2026-09-07 18:39:54 +00:00
Collaborator

Problem

ProjectImporter.addSourceFolderIfExists() created every source classpath
entry via JavaCore.newSourceEntry(path) with no dedicated output location.
src/test/java therefore compiled into the same output as src/main/java
(target/classes for Maven, build/classes/java/main for Gradle). A
subsequent mvn package without clean packed the test classes into the
module jar, and dependent modules then saw "Unresolved compilation
problems" once jdt-mcp was connected to the workspace (arknet test: 17
extra classes in arknet-shared-kernel, 56 in arknet-mcp).

Fix

Test source folders (src/test/java, src/test/resources,
src/test/kotlin) now get an explicit output location —
target/test-classes for Maven, build/classes/java/test for Gradle —
mirroring m2e's behaviour. Main sources keep using the project's default
output (unchanged). ExecutionTools already reads getOutputLocation()
per source entry to build the runtime classpath, so no change was needed
there.

Plain (no build tool) projects are left untouched — there's no established
test-output convention to follow without a build file, and the issue's
expectation (m2e/Gradle parity) doesn't apply to them.

Also removed the now-obsolete "known limitation" row for #84 from
README.md.

#46 (Maven test-scope dependencies)

Verified as already fixed by commit 8084c7d
(-DincludeScope=compile-DincludeScope=test in
addMavenDependencies()). Reimporting fixture-core produces zero
org.junit compile errors.

Closes #84
Refs #46

Verification

  • Module build: mvn -pl org.naturzukunft.jdt.mcp -am compile — clean
  • Full product build: mvn clean package — BUILD SUCCESS
  • tests/smoke-test.sh against the built product: 9/9 passed
  • tests/lifecycle-test.sh against the built product: 5/5 passed
  • Imported tests/fixtures/fixture-parent (copied to a temp dir) via
    stdio against the built product. Generated .classpath for
    fixture-core:
    <classpathentry kind="src" path="src/main/java"/>
    <classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
    ...
    <classpathentry kind="output" path="target/classes"/>
    
    jdt_get_compilation_errors(fixture-core) → 0 errors, 1 unrelated
    pre-existing warning (unused private method). No org.junit errors.

🤖 Generated with Claude Code

https://claude.ai/code/session_016tHV1dzUTdTwMLgx6yotVd

## Problem `ProjectImporter.addSourceFolderIfExists()` created every source classpath entry via `JavaCore.newSourceEntry(path)` with no dedicated output location. `src/test/java` therefore compiled into the same output as `src/main/java` (`target/classes` for Maven, `build/classes/java/main` for Gradle). A subsequent `mvn package` without `clean` packed the test classes into the module jar, and dependent modules then saw "Unresolved compilation problems" once jdt-mcp was connected to the workspace (arknet test: 17 extra classes in `arknet-shared-kernel`, 56 in `arknet-mcp`). ## Fix Test source folders (`src/test/java`, `src/test/resources`, `src/test/kotlin`) now get an explicit output location — `target/test-classes` for Maven, `build/classes/java/test` for Gradle — mirroring m2e's behaviour. Main sources keep using the project's default output (unchanged). `ExecutionTools` already reads `getOutputLocation()` per source entry to build the runtime classpath, so no change was needed there. Plain (no build tool) projects are left untouched — there's no established test-output convention to follow without a build file, and the issue's expectation (m2e/Gradle parity) doesn't apply to them. Also removed the now-obsolete "known limitation" row for #84 from README.md. ## #46 (Maven test-scope dependencies) Verified as already fixed by commit `8084c7d` (`-DincludeScope=compile` → `-DincludeScope=test` in `addMavenDependencies()`). Reimporting `fixture-core` produces zero `org.junit` compile errors. Closes #84 Refs #46 ## Verification - Module build: `mvn -pl org.naturzukunft.jdt.mcp -am compile` — clean - Full product build: `mvn clean package` — BUILD SUCCESS - `tests/smoke-test.sh` against the built product: 9/9 passed - `tests/lifecycle-test.sh` against the built product: 5/5 passed - Imported `tests/fixtures/fixture-parent` (copied to a temp dir) via stdio against the built product. Generated `.classpath` for `fixture-core`: ```xml <classpathentry kind="src" path="src/main/java"/> <classpathentry kind="src" output="target/test-classes" path="src/test/java"/> ... <classpathentry kind="output" path="target/classes"/> ``` `jdt_get_compilation_errors(fixture-core)` → 0 errors, 1 unrelated pre-existing warning (unused private method). No `org.junit` errors. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_016tHV1dzUTdTwMLgx6yotVd
ProjectImporter.addSourceFolderIfExists() created every source entry
via JavaCore.newSourceEntry(path) with no dedicated output location,
so src/test/java and src/main/java both ended up compiling into the
single project output (target/classes for Maven, build/classes/java/main
for Gradle). A subsequent `mvn package` without `clean` then packed the
test classes into the module jar, and other modules depending on it
saw "Unresolved compilation problems" once jdt-mcp was connected to the
workspace (arknet: 17 in arknet-shared-kernel, 56 in arknet-mcp).

Test source folders (src/test/java, src/test/resources, src/test/kotlin)
now get an explicit output location — target/test-classes for Maven,
build/classes/java/test for Gradle — mirroring m2e's behaviour. Main
sources keep using the project's default output. ExecutionTools already
reads getOutputLocation() per source entry, so no change needed there.

Verified #46 (test-scope Maven dependencies) is already fixed since
commit 8084c7d (-DincludeScope=test): reimporting fixture-core produces
no org.junit compile errors.

Closes #84
Refs #46

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016tHV1dzUTdTwMLgx6yotVd
fred merged commit 704ecb90ec into main 2026-09-07 18:39:54 +00:00
fred deleted branch fix/84-test-output-folder 2026-09-07 18:40:00 +00:00
Commenting is not possible because the repository is archived.
No description provided.