plugins { id "java-library" id "maven-publish" } description = "gRPC: Jakarta Servlet" // Set up classpaths and source directories for different servlet tests sourceSets { // Only run these tests if java 11+ is being used if (JavaVersion.current().isJava11Compatible()) { jettyTest { java { include '**/Jetty*.java' } } tomcatTest { java { include '**/Tomcat*.java' } } undertowTest { java { include '**/Undertow*.java' } } } } configurations { itImplementation.extendsFrom(implementation) jettyTestImplementation.extendsFrom(itImplementation) tomcatTestImplementation.extendsFrom(itImplementation) undertowTestImplementation.extendsFrom(itImplementation) } java { sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 } // Mechanically transform sources from grpc-servlet to use the corrected packages def migrate(String name, String inputDir, SourceSet sourceSet) { def outputDir = layout.buildDirectory.dir('generated/sources/jakarta-' + name) sourceSet.java.srcDir tasks.register('migrateSources' + name.capitalize(), Sync) { task -> into(outputDir) from("$inputDir/io/grpc/servlet") { into('io/grpc/servlet/jakarta') filter { String line -> line.replace('javax.servlet', 'jakarta.servlet') .replace('io.grpc.servlet', 'io.grpc.servlet.jakarta') } } } } migrate('main', '../src/main/java', sourceSets.main) // Only build sourceSets and classpaths for tests if using Java 11 if (JavaVersion.current().isJava11Compatible()) { migrate('jettyTest', '../src/jettyTest/java', sourceSets.jettyTest) migrate('tomcatTest', '../src/tomcatTest/java', sourceSets.tomcatTest) migrate('undertowTest', '../src/undertowTest/java', sourceSets.undertowTest) } // Disable checkstyle for this project, since it consists only of generated code tasks.withType(Checkstyle).configureEach { enabled = false } tasks.named("jar").configure { manifest { attributes('Automatic-Module-Name': 'io.grpc.servlet.jakarta') } } dependencies { api project(':grpc-api') compileOnly libraries.jakarta.servlet.api, libraries.javax.annotation implementation project(':grpc-util'), project(':grpc-core'), libraries.guava itImplementation project(':grpc-servlet-jakarta'), project(':grpc-netty'), testFixtures(project(':grpc-core')), libraries.junit itImplementation(project(':grpc-interop-testing')) { // Avoid grpc-netty-shaded dependency exclude group: 'io.grpc', module: 'grpc-alts' exclude group: 'io.grpc', module: 'grpc-xds' } tomcatTestImplementation libraries.tomcat.embed.core jettyTestImplementation libraries.jetty.servlet, libraries.jetty.http2.server undertowTestImplementation libraries.undertow.servlet } // Set up individual classpaths for each test, to avoid any mismatch, // and ensure they are only used when supported by the current jvm if (JavaVersion.current().isJava11Compatible()) { def jetty11Test = tasks.register('jetty11Test', Test) { classpath = sourceSets.jettyTest.runtimeClasspath testClassesDirs = sourceSets.jettyTest.output.classesDirs } def tomcat10Test = tasks.register('tomcat10Test', Test) { classpath = sourceSets.tomcatTest.runtimeClasspath testClassesDirs = sourceSets.tomcatTest.output.classesDirs // Provide a temporary directory for tomcat to be deleted after test finishes def tomcatTempDir = "$buildDir/tomcat_catalina_base" systemProperty 'catalina.base', tomcatTempDir doLast { file(tomcatTempDir).deleteDir() } } tasks.named('compileTomcatTestJava') { JavaCompile task -> task.options.release.set 11 } def undertowTest = tasks.register('undertowTest', Test) { classpath = sourceSets.undertowTest.runtimeClasspath testClassesDirs = sourceSets.undertowTest.output.classesDirs } tasks.named('compileUndertowTestJava') { JavaCompile task -> task.options.release.set 11 } tasks.named("check").configure { dependsOn jetty11Test, tomcat10Test, undertowTest } }