apache / apache/maven-surefire

[SUREFIRE-2259] test-jar includes/excludes are not respected when running "mvn test"

Open
#2,669 0 comments 0 reactions 0 assignees View on GitHub
bug priority:major
Dominant language
Java
Stars
461
Forks
588
Avg merge
1d 8h
Merged PRs (30d)
19

Description

**[Falko Modler](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=famod)** opened **[SUREFIRE-2259](https://issues.apache.org/jira/browse/SUREFIRE-2259?redirect=false)** and commented

Imagine a multi-module project consisting of two modules:
* module A provides a test-jar
* module B is running tests and depends on the test-jar of A

Module A builds the test-jar like this:

```xml


org.apache.maven.plugins
maven-jar-plugin
3.2.2



test-jar



application.properties
org/acme/**




```

So it includes classes under org/acme and application.properties, but that module also has src/test/resources/application*-test*.properties that is not included in test-jar.

Now, if running tests in module B (that uses the test-jar of A), `application-test.properties` ist _not_ on the test classpath when running (from the project root, with our without "clean"):
- mvn install
- mvn package
- mvn test -f B

This is all as expected.

But if just running "mvn test" the `application-test.properties` is suddenly on the classpath, which means that in that case includes/excludes are not respected.

I've attached a reproducer that I originally built for https://github.com/quarkusio/quarkus/issues/42580 which is also where this issue in surefire was spotted.
In that reproducer, module A is "core" and module B is "dist".
Relevant for this issue is `SomeTest` which fails only for "mvn test". `SomeQuarkusTest` is not relevant here.

I'm aware that "test" phase comes before the "package" phase but this is a nasty inconsistency nonetheless.

---

**Affects:** 3.4.0

**Attachments:**
- [q_testjar-properties.zip](https://issues.apache.org/jira/secure/attachment/13071127/q_testjar-properties.zip) (_83.54 kB_)

Contributor guide

Open the contributing guide

Research direction

Start with the attached q_testjar-properties.zip reproducer, focusing on module A (core), module B (dist), and the failing SomeTest; SomeQuarkusTest is not relevant. Run mvn test and compare its test classpath with mvn install, mvn package, and mvn test -f B. Done means application-test.properties is absent when the test-jar includes exclude it.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system, testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.