1plugins { 2 id "java-library" 3 id "maven-publish" 4} 5 6description = "gRPC: Jakarta Servlet" 7sourceCompatibility = 1.8 8targetCompatibility = 1.8 9 10// Set up classpaths and source directories for different servlet tests 11configurations { 12 itImplementation.extendsFrom(implementation) 13 jettyTestImplementation.extendsFrom(itImplementation) 14 tomcatTestImplementation.extendsFrom(itImplementation) 15 undertowTestImplementation.extendsFrom(itImplementation) 16} 17 18sourceSets { 19 undertowTest { 20 java { 21 include '**/Undertow*.java' 22 } 23 } 24 tomcatTest { 25 java { 26 include '**/Tomcat*.java' 27 } 28 } 29 // Only run these tests if java 11+ is being used 30 if (JavaVersion.current().isJava11Compatible()) { 31 jettyTest { 32 java { 33 include '**/Jetty*.java' 34 } 35 } 36 } 37} 38 39// Mechanically transform sources from grpc-servlet to use the corrected packages 40def migrate(String name, String inputDir, SourceSet sourceSet) { 41 def outputDir = layout.buildDirectory.dir('generated/sources/jakarta-' + name) 42 sourceSet.java.srcDir outputDir 43 return tasks.register('migrateSources' + name.capitalize(), Sync) { task -> 44 into(outputDir) 45 from("$inputDir/io/grpc/servlet") { 46 into('io/grpc/servlet/jakarta') 47 filter { String line -> 48 line.replaceAll('javax\\.servlet', 'jakarta.servlet') 49 .replaceAll('io\\.grpc\\.servlet', 'io.grpc.servlet.jakarta') 50 } 51 } 52 } 53} 54 55compileJava.dependsOn migrate('main', '../src/main/java', sourceSets.main) 56 57sourcesJar.dependsOn migrateSourcesMain 58 59// Build the set of sourceSets and classpaths to modify, since Jetty 11 requires Java 11 60// and must be skipped 61compileUndertowTestJava.dependsOn(migrate('undertowTest', '../src/undertowTest/java', sourceSets.undertowTest)) 62compileTomcatTestJava.dependsOn(migrate('tomcatTest', '../src/tomcatTest/java', sourceSets.tomcatTest)) 63if (JavaVersion.current().isJava11Compatible()) { 64 compileJettyTestJava.dependsOn(migrate('jettyTest', '../src/jettyTest/java', sourceSets.jettyTest)) 65} 66 67// Disable checkstyle for this project, since it consists only of generated code 68tasks.withType(Checkstyle) { 69 enabled = false 70} 71 72dependencies { 73 api project(':grpc-api') 74 compileOnly 'jakarta.servlet:jakarta.servlet-api:5.0.0', 75 libraries.javax.annotation 76 77 implementation project(':grpc-core'), 78 libraries.guava 79 80 itImplementation project(':grpc-servlet-jakarta'), 81 project(':grpc-netty'), 82 project(':grpc-core').sourceSets.test.runtimeClasspath, 83 libraries.junit 84 itImplementation(project(':grpc-interop-testing')) { 85 // Avoid grpc-netty-shaded dependency 86 exclude group: 'io.grpc', module: 'grpc-alts' 87 exclude group: 'io.grpc', module: 'grpc-xds' 88 } 89 90 tomcatTestImplementation 'org.apache.tomcat.embed:tomcat-embed-core:10.0.14' 91 92 jettyTestImplementation "org.eclipse.jetty:jetty-servlet:11.0.7", 93 "org.eclipse.jetty.http2:http2-server:11.0.7" 94 95 undertowTestImplementation 'io.undertow:undertow-servlet-jakartaee9:2.2.13.Final' 96} 97 98// Set up individual classpaths for each test, to avoid any mismatch, 99// and ensure they are only used when supported by the current jvm 100check.dependsOn(tasks.register('undertowTest', Test) { 101 classpath = sourceSets.undertowTest.runtimeClasspath 102 testClassesDirs = sourceSets.undertowTest.output.classesDirs 103}) 104check.dependsOn(tasks.register('tomcat10Test', Test) { 105 classpath = sourceSets.tomcatTest.runtimeClasspath 106 testClassesDirs = sourceSets.tomcatTest.output.classesDirs 107 108 // Provide a temporary directory for tomcat to be deleted after test finishes 109 def tomcatTempDir = "$buildDir/tomcat_catalina_base" 110 systemProperty 'catalina.base', tomcatTempDir 111 doLast { 112 file(tomcatTempDir).deleteDir() 113 } 114 115 // tomcat-embed-core 10 presently performs illegal reflective access on 116 // java.io.ObjectStreamClass$Caches.localDescs and sun.rmi.transport.Target.ccl, 117 // see https://lists.apache.org/thread/s0xr7tk2kfkkxfjps9n7dhh4cypfdhyy 118 if (JavaVersion.current().isJava9Compatible()) { 119 jvmArgs += ['--add-opens=java.base/java.io=ALL-UNNAMED', '--add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED'] 120 } 121}) 122// Only run these tests if java 11+ is being used 123if (JavaVersion.current().isJava11Compatible()) { 124 check.dependsOn(tasks.register('jetty11Test', Test) { 125 classpath = sourceSets.jettyTest.runtimeClasspath 126 testClassesDirs = sourceSets.jettyTest.output.classesDirs 127 }) 128} 129