2020import org .gradle .api .Project ;
2121import org .gradle .api .plugins .JavaPlugin ;
2222import org .gradle .api .plugins .jvm .JvmTestSuite ;
23+ import org .gradle .api .tasks .PathSensitivity ;
2324import org .gradle .jvm .toolchain .JavaToolchainService ;
2425import org .gradle .testing .base .TestingExtension ;
2526import org .jspecify .annotations .NullMarked ;
2627
27- import java .util .Map ;
28-
2928@ SuppressWarnings ("UnstableApiUsage" )
3029@ NullMarked
3130public abstract class TestingConventionsPlugin implements Plugin <Project > {
@@ -42,30 +41,41 @@ public void apply(Project project) {
4241 var javaToolchains = extensions .getByType (JavaToolchainService .class );
4342
4443 var samplesDir = layout .getProjectDirectory ().dir ("samples" );
45- var docsSamplesDir = layout .getProjectDirectory ().dir ("src/docs/samples " );
44+ var snippetsDir = layout .getProjectDirectory ().dir ("src/docs/snippets " );
4645
46+ // Unite tests with cross-version support
4747 var testSuite = testing .getSuites ().named ("test" , JvmTestSuite .class , suite -> {
4848 suite .useJUnitJupiter ();
49+ suite .dependencies (dependencies -> dependencies .getImplementation ().add ("org.assertj:assertj-core:3.27.6" ));
50+ });
51+
52+ extensions .create (TestingConventionsExtension .NAME , TestingConventionsExtension .class ,
53+ testSuite .get (), javaToolchains );
54+
55+ // tested samples
56+ testing .getSuites ().register ("testSamples" , JvmTestSuite .class , suite -> {
4957 suite .getTargets ().configureEach (target ->
5058 target .getTestTask ().configure (testTask -> {
5159 testTask .setMaxParallelForks (4 );
5260 if (samplesDir .getAsFile ().exists ()) {
53- testTask .getInputs ().dir (samplesDir );
61+ testTask .getInputs ()
62+ .dir (samplesDir )
63+ .withPathSensitivity (PathSensitivity .RELATIVE )
64+ .withPropertyName ("samples" );
5465 }
55- if (docsSamplesDir .getAsFile ().exists ()) {
56- testTask .getInputs ().dir (docsSamplesDir );
66+ if (snippetsDir .getAsFile ().exists ()) {
67+ testTask .getInputs ()
68+ .dir (snippetsDir )
69+ .withPathSensitivity (PathSensitivity .RELATIVE )
70+ .withPropertyName ("snippets" );
5771 }
5872 }
5973 )
6074 );
6175 suite .dependencies (dependencies -> {
62- dependencies .getImplementation ().add ("org.assertj:assertj-core:3.27.6" );
6376 dependencies .getImplementation ().add ("org.gradle.exemplar:samples-check:1.0.3" );
6477 dependencies .getImplementation ().add ("org.junit.vintage:junit-vintage-engine" );
6578 });
6679 });
67-
68- extensions .create (TestingConventionsExtension .NAME , TestingConventionsExtension .class ,
69- testSuite .get (), javaToolchains );
7080 }
7181}
0 commit comments