|
| 1 | +// Apply the java-library plugin to add support for Java Library |
| 2 | +plugins { |
| 3 | + id 'com.github.sherter.google-java-format' version '0.8' |
| 4 | + id 'maven-publish' |
| 5 | + id 'org.ajoberstar.grgit' version '4.1.0' |
| 6 | +} |
| 7 | +println("Notice: current gradle version is " + gradle.gradleVersion) |
| 8 | +// Additional attribute definition |
| 9 | +ext { |
| 10 | + if (!project.hasProperty("ossrhUsername")) { |
| 11 | + ossrhUsername="xxx" |
| 12 | + } |
| 13 | + |
| 14 | + if (!project.hasProperty("ossrhPassword")) { |
| 15 | + ossrhPassword="xxx" |
| 16 | + } |
| 17 | + // jackson version |
| 18 | + jacksonVersion = "2.11.0" |
| 19 | + commonsIOVersion = "2.4" |
| 20 | + commonsLang3Version = "3.1" |
| 21 | + javapoetVersion = "1.7.0" |
| 22 | + picocliVersion = "3.6.0" |
| 23 | + nettyVersion = "4.1.53.Final" |
| 24 | + nettySMSSLContextVersion = "1.3.0-hsm" |
| 25 | + toml4jVersion = "0.7.2" |
| 26 | + bcprovJDK15onVersion = "1.60" |
| 27 | + webankJavaCryptoVersion = "1.0.0" |
| 28 | + webankHsmCryptoVersion = "1.0.0" |
| 29 | + |
| 30 | + slf4jVersion = "1.7.30" |
| 31 | + junitVersion = "4.12" |
| 32 | + commonsCollections4Version = "4.4" |
| 33 | + guavaVersion = "29.0-jre" |
| 34 | +} |
| 35 | + |
| 36 | +// check.dependsOn integrationTest |
| 37 | +// integrationTest.mustRunAfter test |
| 38 | +allprojects { |
| 39 | + group = 'org.fisco-bcos.java-sdk' |
| 40 | + version = '2.8.0-hsm-SNAPSHOT' |
| 41 | + apply plugin: 'maven' |
| 42 | + apply plugin: 'maven-publish' |
| 43 | + apply plugin: 'idea' |
| 44 | + apply plugin: 'eclipse' |
| 45 | + apply plugin: 'java' |
| 46 | + apply plugin: 'jacoco' |
| 47 | + apply plugin: 'signing' |
| 48 | + |
| 49 | + configurations.all { |
| 50 | + resolutionStrategy.cacheChangingModulesFor 30, 'seconds' |
| 51 | + } |
| 52 | + jacoco { |
| 53 | + toolVersion = "0.8.6" |
| 54 | + } |
| 55 | + jacocoTestReport { |
| 56 | + reports { |
| 57 | + xml.enabled true |
| 58 | + html.enabled false |
| 59 | + } |
| 60 | + } |
| 61 | + sourceCompatibility = 1.8 |
| 62 | + targetCompatibility = 1.8 |
| 63 | + |
| 64 | + // In this section you declare where to find the dependencies of your project |
| 65 | + repositories { |
| 66 | + mavenCentral() |
| 67 | + maven { url "http://maven.aliyun.com/nexus/content/groups/public/" } |
| 68 | + maven { url "https://oss.sonatype.org/service/local/staging/deploy/maven2"} |
| 69 | + maven { url "https://oss.sonatype.org/content/repositories/snapshots" } |
| 70 | + maven {url "https://plugins.gradle.org/m2/"} |
| 71 | + } |
| 72 | + |
| 73 | + dependencies { |
| 74 | + compile ("org.slf4j:slf4j-api:${slf4jVersion}") |
| 75 | + compile ("org.slf4j:slf4j-log4j12:${slf4jVersion}") |
| 76 | + testCompile ("junit:junit:${junitVersion}") |
| 77 | + } |
| 78 | + |
| 79 | + clean.doLast { |
| 80 | + file("dist/apps/").deleteDir() |
| 81 | + file("dist/conf/").deleteDir() |
| 82 | + file("dist/lib/").deleteDir() |
| 83 | + } |
| 84 | +} |
| 85 | + |
| 86 | +subprojects { |
| 87 | + sourceSets { |
| 88 | + main { |
| 89 | + java { |
| 90 | + srcDir 'src/main/java' |
| 91 | + } |
| 92 | + |
| 93 | + resources { |
| 94 | + srcDir 'src/main/resources' |
| 95 | + } |
| 96 | + } |
| 97 | + } |
| 98 | + jar { |
| 99 | + destinationDir file("dist/apps") |
| 100 | + archiveName "fisco-bcos-" + project.name + "-" + version + ".jar" |
| 101 | + |
| 102 | + exclude "**/*.xml" |
| 103 | + exclude "**/*.properties" |
| 104 | + manifest { |
| 105 | + try { |
| 106 | + def repo = grgit.open(currentDir: project.rootDir) |
| 107 | + if (repo != null) { |
| 108 | + def date = new Date().format("yyyy-MM-dd'T'HH:mm:ssZ") |
| 109 | + def branch = repo.branch.getCurrent().getName() |
| 110 | + def commit = repo.head().getAbbreviatedId(40) |
| 111 | + |
| 112 | + attributes(["Implementation-Timestamp": date, |
| 113 | + "Git-Branch" : branch, |
| 114 | + "Git-Commit" : commit |
| 115 | + ]) |
| 116 | + |
| 117 | + logger.info(" Commit : ") |
| 118 | + logger.info(" => date: {}", date) |
| 119 | + logger.info(" => branch: {}", branch) |
| 120 | + logger.info(" => commit: {}", commit) |
| 121 | + } |
| 122 | + } catch (Exception e) { |
| 123 | + logger.warn(' .git not exist, cannot found commit info, e: {}', e) |
| 124 | + } |
| 125 | + } from sourceSets.main.output |
| 126 | + |
| 127 | + doLast { |
| 128 | + copy { |
| 129 | + from file("src/test/resources/") |
| 130 | + into "dist/conf" |
| 131 | + } |
| 132 | + copy { |
| 133 | + from configurations.runtime |
| 134 | + into "dist/lib" |
| 135 | + } |
| 136 | + copy { |
| 137 | + from file("build/libs/") |
| 138 | + into "dist/apps" |
| 139 | + } |
| 140 | + } |
| 141 | + } |
| 142 | +} |
| 143 | + |
| 144 | +sourceSets { |
| 145 | + main { |
| 146 | + java { |
| 147 | + srcDir "sdk-core/src/main/java" |
| 148 | + srcDir "sdk-crypto/src/main/java" |
| 149 | + srcDir "sdk-abi/src/main/java" |
| 150 | + srcDir "sdk-amop/src/main/java" |
| 151 | + srcDir "sdk-service/src/main/java" |
| 152 | + srcDir "sdk-transaction/src/main/java" |
| 153 | + srcDir "sdk-codegen/src/main/java" |
| 154 | + } |
| 155 | + |
| 156 | + resources { |
| 157 | + srcDir 'src/main/resources' |
| 158 | + } |
| 159 | + } |
| 160 | + integrationTest { |
| 161 | + copy { |
| 162 | + from file('src/test/resources/amop/') |
| 163 | + into 'conf/amop' |
| 164 | + } |
| 165 | + java { |
| 166 | + compileClasspath += main.output + test.output |
| 167 | + runtimeClasspath += main.output + test.output |
| 168 | + srcDir file('src/integration-test/java') |
| 169 | + } |
| 170 | + resources.srcDir file('src/integration-test/resources') |
| 171 | + } |
| 172 | +} |
| 173 | + |
| 174 | +googleJavaFormat { |
| 175 | + options style: 'AOSP' |
| 176 | + source = sourceSets*.allJava |
| 177 | + include '**/*.java' |
| 178 | +} |
| 179 | + |
| 180 | +configurations { |
| 181 | + integrationTestCompile.extendsFrom testCompile |
| 182 | + integrationTestRuntime.extendsFrom testRuntime |
| 183 | +} |
| 184 | + |
| 185 | +task integrationTest(type: Test) { |
| 186 | + testClassesDirs = sourceSets.integrationTest.output.classesDirs |
| 187 | + classpath = sourceSets.integrationTest.runtimeClasspath |
| 188 | +} |
| 189 | + |
| 190 | +dependencies { |
| 191 | + compile ("org.bouncycastle:bcprov-jdk15on:${bcprovJDK15onVersion}") |
| 192 | + compile ("org.apache.commons:commons-lang3:${commonsLang3Version}") |
| 193 | + compile ("io.netty:netty-all:${nettyVersion}") |
| 194 | + compile ("org.fisco-bcos:netty-sm-ssl-context:${nettySMSSLContextVersion}") |
| 195 | + compile ("com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}") |
| 196 | + compile ("commons-io:commons-io:${commonsIOVersion}") |
| 197 | + compile ("com.squareup:javapoet:${javapoetVersion}") |
| 198 | + compile ("info.picocli:picocli:${picocliVersion}") |
| 199 | + compile ("com.webank:webank-blockchain-java-crypto:${webankJavaCryptoVersion}") |
| 200 | + compile ("com.moandjiezana.toml:toml4j:${toml4jVersion}") |
| 201 | + compile ("com.webank:webank-blockchain-hsm-crypto:${webankHsmCryptoVersion}") |
| 202 | + testCompile ("org.apache.commons:commons-collections4:${commonsCollections4Version}") |
| 203 | + testCompile ("com.google.guava:guava:${guavaVersion}") |
| 204 | +} |
| 205 | + |
| 206 | +javadoc { |
| 207 | + options.addStringOption('Xdoclint:none', '-quiet') |
| 208 | + options.addStringOption('encoding', 'UTF-8') |
| 209 | + options.addStringOption('charSet', 'UTF-8') |
| 210 | +} |
| 211 | + |
| 212 | +task sourcesJar(type: Jar) { |
| 213 | + from sourceSets.main.allJava |
| 214 | + archiveClassifier = 'sources' |
| 215 | +} |
| 216 | + |
| 217 | +task javadocJar(type: Jar) { |
| 218 | + from javadoc |
| 219 | + archiveClassifier = 'javadoc' |
| 220 | +} |
| 221 | + |
| 222 | +publishing { |
| 223 | + publications { |
| 224 | + mavenJava(MavenPublication) { |
| 225 | + |
| 226 | + artifactId "fisco-bcos-" + project.name |
| 227 | + groupId project.group |
| 228 | + version project.version |
| 229 | + |
| 230 | + from components.java |
| 231 | + artifact sourcesJar |
| 232 | + artifact javadocJar |
| 233 | + pom { |
| 234 | + name = 'fisco-bcos' |
| 235 | + description = 'fisco-bcos java-sdk' |
| 236 | + url = 'http://www.fisco-bcos.org' |
| 237 | + |
| 238 | + licenses { |
| 239 | + license { |
| 240 | + name = 'The Apache License, Version 2.0' |
| 241 | + url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' |
| 242 | + } |
| 243 | + } |
| 244 | + developers { |
| 245 | + developer { |
| 246 | + id = 'zhangsan' |
| 247 | + name = 'zhangsan' |
| 248 | + email = 'zhangsan@example.com' |
| 249 | + } |
| 250 | + } |
| 251 | + scm { |
| 252 | + connection = 'https://github.com/FISCO-BCOS/java-sdk.git' |
| 253 | + url = 'https://github.com/FISCO-BCOS/java-sdk.git' |
| 254 | + } |
| 255 | + } |
| 256 | + } |
| 257 | + } |
| 258 | + repositories { |
| 259 | + maven { |
| 260 | + def releasesRepoURL = "https://oss.sonatype.org/service/local/staging/deploy/maven2" |
| 261 | + def snapshotsRepoURL = "https://oss.sonatype.org/content/repositories/snapshots" |
| 262 | + url = !version.endsWith("SNAPSHOT") ? releasesRepoURL : snapshotsRepoURL |
| 263 | + |
| 264 | + credentials { |
| 265 | + username ossrhUsername |
| 266 | + password ossrhPassword |
| 267 | + } |
| 268 | + } |
| 269 | + } |
| 270 | + |
| 271 | + signing { |
| 272 | + sign publishing.publications.mavenJava |
| 273 | + } |
| 274 | +} |
| 275 | + |
| 276 | +jar { |
| 277 | + // destinationDir file('dist/apps') |
| 278 | + archiveName "fisco-bcos-" + project.name + '-' + project.version + '.jar' |
| 279 | + exclude '**/*.xml' |
| 280 | + exclude '**/*.properties' |
| 281 | + |
| 282 | + manifest { |
| 283 | + try { |
| 284 | + def repo = grgit.open(currentDir: project.rootDir) |
| 285 | + if (repo != null) { |
| 286 | + def date = new Date().format("yyyy-MM-dd'T'HH:mm:ssZ") |
| 287 | + def branch = repo.branch.getCurrent().getName() |
| 288 | + def commit = repo.head().getAbbreviatedId(40) |
| 289 | + |
| 290 | + attributes(["Implementation-Timestamp": date, |
| 291 | + "Git-Branch" : branch, |
| 292 | + "Git-Commit" : commit |
| 293 | + ]) |
| 294 | + |
| 295 | + logger.info(" Commit : ") |
| 296 | + logger.info(" => date: {}", date) |
| 297 | + logger.info(" => branch: {}", branch) |
| 298 | + logger.info(" => commit: {}", commit) |
| 299 | + } |
| 300 | + } catch (Exception e) { |
| 301 | + logger.warn(' .git not exist, cannot found commit info, e: {}', e) |
| 302 | + } |
| 303 | + } from sourceSets.main.output |
| 304 | + |
| 305 | + doLast { |
| 306 | + copy { |
| 307 | + from destinationDir |
| 308 | + into 'dist/apps' |
| 309 | + } |
| 310 | + copy { |
| 311 | + from configurations.runtime |
| 312 | + into 'dist/lib' |
| 313 | + } |
| 314 | + copy { |
| 315 | + from file('src/test/resources/config-example.toml') |
| 316 | + from file('src/test/resources/applicationContext-sample.xml') |
| 317 | + from file('src/test/resources/log4j.properties') |
| 318 | + into 'dist/conf' |
| 319 | + } |
| 320 | + } |
| 321 | +} |
| 322 | +check.dependsOn jacocoTestReport |
0 commit comments