From c36be2763c4b75915cf079fe3d93d9d7c341b230 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Basl=C3=A9?= Date: Fri, 25 Oct 2019 10:56:45 +0200 Subject: [PATCH] [build] Allow selection of relevant netty-native-transport from CLI The `forceTranport` property can be used to choose between `nio` and `native` when running Gradle tasks like tests. This allows to select the underlying transport to active, eg. when running a test matrix in CI. --- build.gradle | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 83270f4c5b..cd53ab32f3 100644 --- a/build.gradle +++ b/build.gradle @@ -252,8 +252,32 @@ configure(rootProject) { project -> compile "io.netty:netty-handler:${nettyVersion}" compile "io.netty:netty-codec-http:${nettyVersion}" - compile "io.netty:netty-transport-native-epoll:${nettyVersion}:linux-x86_64" - optional "io.netty:netty-transport-native-kqueue:${nettyVersion}" + + //transport resolution: typical build forces epoll but not kqueue transitively + //on the other hand, if we want to make transport-specific tests, we'll make all + // native optional at compile time and add correct native/nio to testRuntime + if (project.hasProperty("forceTransport")) { + //so that the main code compiles + optional "io.netty:netty-transport-native-epoll:${nettyVersion}" + optional "io.netty:netty-transport-native-kqueue:${nettyVersion}" + //now we explicitly add correctly qualified native, or do nothing if we want to test NIO + if (forceTransport == "native") { + if (osdetector.os == "osx") { + testRuntime "io.netty:netty-transport-native-kqueue:${nettyVersion}${os_suffix}" + } + else if (osdetector.os == "linux") { + testRuntime "io.netty:netty-transport-native-epoll:${nettyVersion}${os_suffix}" + } + } + else if (forceTransport != "nio") { + throw new InvalidUserDataException("invalid -PforceTranport option " + forceTransport + ", should be native|nio") + } + } + else { + //classic build to be distributed + compile "io.netty:netty-transport-native-epoll:${nettyVersion}:linux-x86_64" + optional "io.netty:netty-transport-native-kqueue:${nettyVersion}" + } // Testing testCompile "com.fasterxml.jackson.core:jackson-databind:$jacksonDatabindVersion"