1plugins { 2 id "java-library" 3 id "maven-publish" 4} 5 6description = "gRPC: Servlet" 7 8// javax.servlet-api 4.0 requires a minimum of Java 8, so we might as well use that source level 9sourceCompatibility = 1.8 10targetCompatibility = 1.8 11 12def jettyVersion = '10.0.7' 13 14configurations { 15 itImplementation.extendsFrom(implementation) 16 undertowTestImplementation.extendsFrom(itImplementation) 17 tomcatTestImplementation.extendsFrom(itImplementation) 18 jettyTestImplementation.extendsFrom(itImplementation) 19} 20 21sourceSets { 22 // Create a test sourceset for each classpath - could be simplified if we made new test directories 23 undertowTest {} 24 tomcatTest {} 25 26 // Only compile these tests if java 11+ is being used 27 if (JavaVersion.current().isJava11Compatible()) { 28 jettyTest {} 29 } 30} 31 32dependencies { 33 api project(':grpc-api') 34 compileOnly 'javax.servlet:javax.servlet-api:4.0.1', 35 libraries.javax.annotation // java 9, 10 needs it 36 37 implementation project(':grpc-core'), 38 libraries.guava 39 40 testImplementation 'javax.servlet:javax.servlet-api:4.0.1', 41 'org.jetbrains.kotlinx:lincheck:2.14.1' 42 43 itImplementation project(':grpc-servlet'), 44 project(':grpc-netty'), 45 project(':grpc-core').sourceSets.test.runtimeClasspath, 46 libraries.junit 47 itImplementation(project(':grpc-interop-testing')) { 48 // Avoid grpc-netty-shaded dependency 49 exclude group: 'io.grpc', module: 'grpc-alts' 50 exclude group: 'io.grpc', module: 'grpc-xds' 51 } 52 53 undertowTestImplementation 'io.undertow:undertow-servlet:2.2.14.Final' 54 55 tomcatTestImplementation 'org.apache.tomcat.embed:tomcat-embed-core:9.0.56' 56 57 jettyTestImplementation "org.eclipse.jetty:jetty-servlet:${jettyVersion}", 58 "org.eclipse.jetty.http2:http2-server:${jettyVersion}", 59 "org.eclipse.jetty:jetty-client:${jettyVersion}" 60 project(':grpc-testing') 61} 62 63test { 64 if (JavaVersion.current().isJava9Compatible()) { 65 jvmArgs += [ 66 // required for Lincheck 67 '--add-opens=java.base/jdk.internal.misc=ALL-UNNAMED', 68 '--add-exports=java.base/jdk.internal.util=ALL-UNNAMED', 69 ] 70 } 71} 72 73// Set up individual classpaths for each test, to avoid any mismatch, 74// and ensure they are only used when supported by the current jvm 75check.dependsOn(tasks.register('undertowTest', Test) { 76 classpath = sourceSets.undertowTest.runtimeClasspath 77 testClassesDirs = sourceSets.undertowTest.output.classesDirs 78}) 79check.dependsOn(tasks.register('tomcat9Test', Test) { 80 classpath = sourceSets.tomcatTest.runtimeClasspath 81 testClassesDirs = sourceSets.tomcatTest.output.classesDirs 82 83 // Provide a temporary directory for tomcat to be deleted after test finishes 84 def tomcatTempDir = "$buildDir/tomcat_catalina_base" 85 systemProperty 'catalina.base', tomcatTempDir 86 doLast { 87 file(tomcatTempDir).deleteDir() 88 } 89 90 // tomcat-embed-core 9 presently performs illegal reflective access on 91 // java.io.ObjectStreamClass$Caches.localDescs and sun.rmi.transport.Target.ccl, 92 // see https://lists.apache.org/thread/s0xr7tk2kfkkxfjps9n7dhh4cypfdhyy 93 if (JavaVersion.current().isJava9Compatible()) { 94 jvmArgs += ['--add-opens=java.base/java.io=ALL-UNNAMED', '--add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED'] 95 } 96}) 97 98// Only run these tests if java 11+ is being used 99if (JavaVersion.current().isJava11Compatible()) { 100 check.dependsOn(tasks.register('jettyTest', Test) { 101 classpath = sourceSets.jettyTest.runtimeClasspath 102 testClassesDirs = sourceSets.jettyTest.output.classesDirs 103 }) 104} 105 106jacocoTestReport { 107 executionData undertowTest, tomcat9Test 108 if (JavaVersion.current().isJava11Compatible()) { 109 executionData jettyTest 110 } 111} 112