Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gradle 7: test.moduleOptions.runOnClasspath doesn't work for test compilation #184

Closed
shutyaev opened this issue Apr 16, 2021 · 2 comments
Closed

Comments

@shutyaev
Copy link

In my project I get the following error for compileTestJava task:

error: package org.junit.jupiter.params is not visible
import org.junit.jupiter.params.ParameterizedTest;
                        ^
  (package org.junit.jupiter.params is declared in module org.junit.jupiter.params, but module org.foo does not read it)

although I've explicitly disabled modules for tests with:

test {
	useJUnitPlatform()
	moduleOptions {
		runOnClasspath = true
	}
}

and I've disabled the gradle 7 inferModulePath with

java {
	modularity.inferModulePath = false
}
tasks.withType(JavaCompile) {
	modularity.inferModulePath = false
}

Here's an isolated simple project demonstrating the behavior: https://github.com/shutyaev/gradle-7-test-issue

@siordache
Copy link
Collaborator

Tests are always compiled on the module-path. runOnClasspath specifies only how the tests should be run.

The error you get for compileTestJava is due to this issue. The next release, which will come soon, will fix it.

Until then, you can fix your build by adding the following compiler flags to the module-info.test file:

--add-modules
  org.junit.jupiter.params,org.junit.platform.commons

--add-reads
  org.foo=org.junit.jupiter.params

--add-opens
    org.foo/org.foo=org.junit.platform.commons,ALL-UNNAMED

--add-exports
  org.junit.platform.commons/org.junit.platform.commons.util=ALL-UNNAMED

--add-exports
  org.junit.platform.commons/org.junit.platform.commons.logging=ALL-UNNAMED

--add-exports
  org.junit.platform.engine/org.junit.platform.engine.support.filter=org.junit.jupiter.engine,ALL-UNNAMED

@shutyaev
Copy link
Author

@siordache thanks for the quick and thorough reply! Looking forward to the new version!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants