|
| 1 | +plugins { |
| 2 | + id 'com.google.protobuf' |
| 3 | + id 'cpp' |
| 4 | + id 'java' |
| 5 | + id 'idea' |
| 6 | +} |
| 7 | + |
| 8 | +apply plugin: 'com.jfrog.bintray' |
| 9 | +apply plugin: 'maven' |
| 10 | +apply plugin: 'maven-publish' |
| 11 | + |
| 12 | +task ciVersion { |
| 13 | + description = "Creates a continuous-delivery friendly version number for the service" |
| 14 | + |
| 15 | + def releaseType = project.hasProperty('releaseType') ? project.property('releaseType') : System.getenv('RELEASE_TYPE') |
| 16 | + def commitHash = project.hasProperty('commitHash') ? project.property('commitHash') : System.getenv('COMMIT_HASH') |
| 17 | + |
| 18 | + if (releaseType == 'release' || releaseType == 'r') { |
| 19 | + project.version = project.version |
| 20 | + } else if (releaseType == 'releaseCandidate' || releaseType == 'rc') { |
| 21 | + project.version = "${project.version}-RC".toString() |
| 22 | + } else if (releaseType == 'snapshot' || releaseType == 's') { |
| 23 | + if (commitHash) { |
| 24 | + project.version = "${project.version}-SNAPSHOT-${commitHash}".toString() |
| 25 | + } else { |
| 26 | + project.version = "${project.version}-SNAPSHOT".toString() |
| 27 | + } |
| 28 | + } else { |
| 29 | + logger.info("Property 'releaseType' was not specified. Defaulting to 'snapshot'") |
| 30 | + if (commitHash) { |
| 31 | + project.version = "${project.version}-SNAPSHOT-${commitHash}".toString() |
| 32 | + } else { |
| 33 | + project.version = "${project.version}-SNAPSHOT".toString() |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + println "Setting CI Version for '${project.name}': ${version}" |
| 38 | +} |
| 39 | +build.dependsOn ciVersion |
| 40 | + |
| 41 | +def pluginPrefix = "rsocket-rpc-java-${osdetector.os}-${osdetector.arch}" |
| 42 | +def pluginName = "${pluginPrefix}.exe" |
| 43 | +def artifactStagingPath = "$buildDir/artifacts" as File |
| 44 | +def pathToPlugin = "${artifactStagingPath.getPath()}/${pluginName}" |
| 45 | + |
| 46 | +repositories { |
| 47 | + jcenter() |
| 48 | + maven { |
| 49 | + url = 'https://dl.bintray.com/netifi/netifi-oss' |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +sourceCompatibility = 1.8 |
| 54 | +targetCompatibility = 1.8 |
| 55 | + |
| 56 | +dependencies { |
| 57 | + compileOnly 'io.projectreactor:reactor-core:3.1.7.RELEASE' |
| 58 | + compileOnly 'com.google.protobuf:protobuf-java:3.6.0' |
| 59 | + compileOnly 'javax.inject:javax.inject:1' |
| 60 | +} |
| 61 | + |
| 62 | +protobuf { |
| 63 | + generatedFilesBaseDir = "${projectDir}/src/generated" |
| 64 | + |
| 65 | + protoc { |
| 66 | + artifact = 'com.google.protobuf:protoc:3.6.0' |
| 67 | + } |
| 68 | + plugins { |
| 69 | + rsocketRpc { |
| 70 | + path = pathToPlugin |
| 71 | + } |
| 72 | + } |
| 73 | + generateProtoTasks { |
| 74 | + all().each { task -> |
| 75 | + task.dependsOn ':protobuf-rpc:java_pluginExecutable' |
| 76 | + task.inputs.file "$pathToPlugin" |
| 77 | + task.inputs.file "${rootProject.projectDir}/build.gradle" |
| 78 | + task.plugins { |
| 79 | + rsocketRpc {} |
| 80 | + } |
| 81 | + } |
| 82 | + } |
| 83 | +} |
| 84 | + |
| 85 | +// Adds space-delimited arguments from the environment variable env to the |
| 86 | +// argList. |
| 87 | +def addEnvArgs = { env, argList -> |
| 88 | + def value = System.getenv(env) |
| 89 | + if (value != null) { |
| 90 | + value.split(' +').each() { it -> argList.add(it) } |
| 91 | + } |
| 92 | +} |
| 93 | + |
| 94 | +// Adds corresponding "-l" option to the argList if libName is not found in |
| 95 | +// LDFLAGS. This is only used for Mac because when building for uploadArchives |
| 96 | +// artifacts, we add the ".a" files directly to LDFLAGS and without "-l" in |
| 97 | +// order to get statically linked, otherwise we add the libraries through "-l" |
| 98 | +// so that they can be searched for in default search paths. |
| 99 | +def addLibraryIfNotLinked = { libName, argList -> |
| 100 | + def ldflags = System.env.LDFLAGS |
| 101 | + if (ldflags == null || !ldflags.contains('lib' + libName + '.a')) { |
| 102 | + argList.add('-l' + libName) |
| 103 | + } |
| 104 | +} |
| 105 | + |
| 106 | +String arch = rootProject.hasProperty('targetArch') ? rootProject.targetArch : osdetector.arch |
| 107 | +boolean vcDisable = rootProject.hasProperty('vcDisable') ? rootProject.vcDisable : false |
| 108 | + |
| 109 | +model { |
| 110 | + toolChains { |
| 111 | + // If you have both VC and Gcc installed, VC will be selected, unless you |
| 112 | + // set 'vcDisable=true' |
| 113 | + if (!vcDisable) { |
| 114 | + visualCpp(VisualCpp) { |
| 115 | + } |
| 116 | + } |
| 117 | + gcc(Gcc) { |
| 118 | + target("ppcle_64") |
| 119 | + } |
| 120 | + clang(Clang) { |
| 121 | + } |
| 122 | + } |
| 123 | + |
| 124 | + platforms { |
| 125 | + x86_32 { |
| 126 | + architecture "x86" |
| 127 | + } |
| 128 | + x86_64 { |
| 129 | + architecture "x86_64" |
| 130 | + } |
| 131 | + ppcle_64 { |
| 132 | + architecture "ppcle_64" |
| 133 | + } |
| 134 | + } |
| 135 | + |
| 136 | + components { |
| 137 | + java_plugin(NativeExecutableSpec) { |
| 138 | + if (arch in ['x86_32', 'x86_64', 'ppcle_64']) { |
| 139 | + // If arch is not within the defined platforms, we do not specify the |
| 140 | + // targetPlatform so that Gradle will choose what is appropriate. |
| 141 | + targetPlatform arch |
| 142 | + } |
| 143 | + baseName "$pluginPrefix" |
| 144 | + } |
| 145 | + } |
| 146 | + |
| 147 | + binaries { |
| 148 | + all { |
| 149 | + if (toolChain in Gcc || toolChain in Clang) { |
| 150 | + cppCompiler.define("RSOCKET_RPC_VERSION", version) |
| 151 | + cppCompiler.args "--std=c++0x" |
| 152 | + addEnvArgs("CXXFLAGS", cppCompiler.args) |
| 153 | + addEnvArgs("CPPFLAGS", cppCompiler.args) |
| 154 | + if (osdetector.os == "osx") { |
| 155 | + cppCompiler.args "-mmacosx-version-min=10.7", "-stdlib=libc++" |
| 156 | + addLibraryIfNotLinked('protoc', linker.args) |
| 157 | + addLibraryIfNotLinked('protobuf', linker.args) |
| 158 | + } else if (osdetector.os == "windows") { |
| 159 | + linker.args "-static", "-lprotoc", "-lprotobuf", "-static-libgcc", "-static-libstdc++", |
| 160 | + "-s" |
| 161 | + } else { |
| 162 | + // Link protoc, protobuf, libgcc and libstdc++ statically. |
| 163 | + // Link other (system) libraries dynamically. |
| 164 | + // Clang under OSX doesn't support these options. |
| 165 | + linker.args "-Wl,-Bstatic", "-lprotoc", "-lprotobuf", "-static-libgcc", |
| 166 | + "-static-libstdc++", |
| 167 | + "-Wl,-Bdynamic", "-lpthread", "-s" |
| 168 | + } |
| 169 | + addEnvArgs("LDFLAGS", linker.args) |
| 170 | + } else if (toolChain in VisualCpp) { |
| 171 | + cppCompiler.define("RSOCKET_RPC_VERSION", version) |
| 172 | + cppCompiler.args "/EHsc", "/MT" |
| 173 | + if (rootProject.hasProperty('vcProtobufInclude')) { |
| 174 | + cppCompiler.args "/I${rootProject.vcProtobufInclude}" |
| 175 | + } |
| 176 | + linker.args "libprotobuf.lib", "libprotoc.lib" |
| 177 | + if (rootProject.hasProperty('vcProtobufLibs')) { |
| 178 | + linker.args "/LIBPATH:${rootProject.vcProtobufLibs}" |
| 179 | + } |
| 180 | + } |
| 181 | + } |
| 182 | + } |
| 183 | +} |
| 184 | + |
| 185 | +task buildArtifacts(type: Copy) { |
| 186 | + println 'generating artifacts' |
| 187 | + dependsOn 'java_pluginExecutable' |
| 188 | + from("$buildDir/exe/java_plugin") { |
| 189 | + if (osdetector.os != 'windows') { |
| 190 | + rename pluginPrefix, '$0.exe' |
| 191 | + } |
| 192 | + } |
| 193 | + into artifactStagingPath |
| 194 | +} |
| 195 | + |
| 196 | +compileJava.dependsOn ':protobuf-rpc:buildArtifacts' |
| 197 | +compileJava.dependsOn ':protobuf-rpc:generateProto' |
| 198 | + |
| 199 | +clean { |
| 200 | + delete protobuf.generatedFilesBaseDir |
| 201 | +} |
| 202 | + |
| 203 | +artifacts { |
| 204 | + archives("$pathToPlugin" as File) { |
| 205 | + classifier osdetector.os + "-" + osdetector.arch |
| 206 | + type "exe" |
| 207 | + extension "exe" |
| 208 | + builtBy buildArtifacts |
| 209 | + } |
| 210 | +} |
| 211 | + |
| 212 | +//publishing { |
| 213 | +// publications { |
| 214 | +// maven(MavenPublication) { |
| 215 | +// artifactId "${project.ext.artifactName}" |
| 216 | +// artifact(pathToPlugin) { |
| 217 | +// classifier osdetector.os + "-" + osdetector.arch |
| 218 | +// builtBy buildArtifacts |
| 219 | +// } |
| 220 | +// } |
| 221 | +// } |
| 222 | +//} |
| 223 | + |
| 224 | + |
| 225 | +if ("$version".contains('SNAPSHOT') || "$version".contains('RC')) { |
| 226 | + publishing { |
| 227 | + publications { |
| 228 | + maven(MavenPublication) { |
| 229 | + artifactId "${project.ext.artifactName}" |
| 230 | + artifact(pathToPlugin) { |
| 231 | + classifier osdetector.os + "-" + osdetector.arch |
| 232 | + builtBy buildArtifacts |
| 233 | + } |
| 234 | + } |
| 235 | + } |
| 236 | + repositories { |
| 237 | + maven { |
| 238 | + url = version.contains('SNAPSHOT') ? 'https://artifactory.netifiinc.com/artifactory/libs-snapshot-local' : 'https://artifactory.netifiinc.com/artifactory/libs-release-local' |
| 239 | + credentials { |
| 240 | + username = project.hasProperty('netifiArtifactoryUsername') ? project.property('netifiArtifactoryUsername') : System.getenv('NETIFI_ARTIFACTORY_USERNAME') |
| 241 | + password = project.hasProperty('netifiArtifactoryPassword') ? project.property('netifiArtifactoryPassword') : System.getenv('NETIFI_ARTIFACTORY_PASSWORD') |
| 242 | + } |
| 243 | + } |
| 244 | + } |
| 245 | + } |
| 246 | +} else { |
| 247 | + publishing { |
| 248 | + publications { |
| 249 | + maven(MavenPublication) { |
| 250 | + artifactId "${project.ext.artifactName}" |
| 251 | + artifact(pathToPlugin) { |
| 252 | + classifier osdetector.os + "-" + osdetector.arch |
| 253 | + builtBy buildArtifacts |
| 254 | + } |
| 255 | + } |
| 256 | + } |
| 257 | + } |
| 258 | + |
| 259 | + bintray { |
| 260 | + user = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER') |
| 261 | + key = project.hasProperty('bintrayKey') ? project.property('bintrayKey') : System.getenv('f') |
| 262 | + |
| 263 | + publications = ['maven'] |
| 264 | + |
| 265 | + //dryRun = true |
| 266 | + publish = (osdetector.os == 'osx') |
| 267 | + override = true |
| 268 | + |
| 269 | + pkg { |
| 270 | + repo = 'netifi-oss' |
| 271 | + name = "${artifactName}".toString() |
| 272 | + userOrg = 'netifi' |
| 273 | + desc = "${project.description}" |
| 274 | + websiteUrl = 'https://github.com/netifi/rsocket-rpc-java' |
| 275 | + issueTrackerUrl = 'https://github.com/netifi/rsocket-rpc-java/issues' |
| 276 | + vcsUrl = 'https://github.com/netifi/rsocket-rpc-java.git' |
| 277 | + licenses = ['Apache-2.0'] |
| 278 | + githubRepo = 'netifi/rsocket-rpc-java' |
| 279 | + githubReleaseNotesFile = 'CHANGELOG.md' |
| 280 | + |
| 281 | + version { |
| 282 | + name = "$project.version".toString() |
| 283 | + } |
| 284 | + } |
| 285 | + } |
| 286 | +} |
0 commit comments