Skip to content

Commit

Permalink
testCompileOnly extends compileOnly for Whitebox Test Suites
Browse files Browse the repository at this point in the history
Resolves #51
  • Loading branch information
jjohannes committed Nov 18, 2024
1 parent 5ada29e commit 9276ebb
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Version 1.5
* [#47](https://github.com/gradlex-org/java-module-testing/issues/47) Add support for Classpath Test Suites
* [#51](https://github.com/gradlex-org/java-module-testing/issues/51) testCompileOnly extends compileOnly for Whitebox Test Suites

## Version 1.4
* [#2](https://github.com/gradlex-org/java-module-testing/issues/2) New approach to split Module Path and Classpath for whitebox testing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ private void configureJvmTestSuiteForWhitebox(JvmTestSuite jvmTestSuite, Whitebo
tasks.named(testSources.getCompileJavaTaskName(), JavaCompile.class, compileJava -> {
SourceSet sourcesUnderTest = whiteboxJvmTestSuite.getSourcesUnderTest().get();

configurations.getByName(testSources.getCompileOnlyConfigurationName()).extendsFrom(
configurations.getByName(sourcesUnderTest.getCompileOnlyConfigurationName()));

compileJava.setClasspath(sourcesUnderTest.getOutput().plus(configurations.getByName(testSources.getCompileClasspathConfigurationName())));

WhiteboxTestCompileArgumentProvider argumentProvider = (WhiteboxTestCompileArgumentProvider) compileJava.getOptions().getCompilerArgumentProviders().stream()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.gradlex.javamodule.testing.test

import org.gradle.testkit.runner.TaskOutcome
import org.gradlex.javamodule.testing.test.fixture.GradleBuild
import spock.lang.Specification

class CoreFunctionailtyTest extends Specification {

@Delegate
GradleBuild build = new GradleBuild()

def "testCompileOnly extends compileOnly for whitebox test suites"() {
given:
appBuildFile << '''
javaModuleTesting.classpath(testing.suites["test"])
dependencies {
compileOnly("jakarta.servlet:jakarta.servlet-api:6.1.0")
}
'''
file("app/src/main/java/org/example/app/ServletImpl.java") << '''
package org.example.app;
public abstract class ServletImpl implements jakarta.servlet.Servlet { }
'''
file("app/src/test/java/org/example/app/test/ServletMock.java") << '''
package org.example.app.test;
public abstract class ServletMock extends org.example.app.ServletImpl { }
'''
appModuleInfoFile << '''
module org.example.app {
requires static jakarta.servlet;
}
'''

when:
def result = runner('compileTestJava').build()

then:
result.task(':app:compileTestJava').outcome == TaskOutcome.SUCCESS
}
}

0 comments on commit 9276ebb

Please sign in to comment.