| 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 the required minimum Java version is being used |
| if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_17)) { |
| jettyTest { |
| java { |
| include '**/Jetty*.java' |
| } |
| } |
| } |
| if (JavaVersion.current().isJava11Compatible()) { |
| 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) |
| // Increment when changing the filter, to inform Gradle it needs to rebuild |
| inputs.property("filter-version", "1") |
| 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') |
| .replace('org.eclipse.jetty.http2.parser', 'org.eclipse.jetty.http2') |
| .replace('org.eclipse.jetty.servlet', 'org.eclipse.jetty.ee10.servlet') |
| } |
| } |
| } |
| } |
| |
| migrate('main', '../src/main/java', sourceSets.main) |
| |
| // Only build sourceSets and classpaths for tests if using the required minimum Java version |
| if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_17)) { |
| migrate('jettyTest', '../src/jettyTest/java', sourceSets.jettyTest) |
| } |
| if (JavaVersion.current().isJava11Compatible()) { |
| 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 |
| |
| 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().isCompatibleWith(JavaVersion.VERSION_17)) { |
| def jetty11Test = tasks.register('jetty11Test', Test) { |
| classpath = sourceSets.jettyTest.runtimeClasspath |
| testClassesDirs = sourceSets.jettyTest.output.classesDirs |
| } |
| tasks.named('compileJettyTestJava') { JavaCompile task -> |
| task.options.release.set 9 |
| } |
| tasks.named("check").configure { |
| dependsOn jetty11Test |
| } |
| } |
| if (JavaVersion.current().isJava11Compatible()) { |
| 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 tomcat10Test, undertowTest |
| } |
| } |