|
3 | 3 | * |
4 | 4 | * This generated file contains a sample Java Library project to get you started. |
5 | 5 | * For more details take a look at the Java Libraries chapter in the Gradle |
6 | | - * user guide available at https://docs.gradle.org/4.3/userguide/java_library_plugin.html |
| 6 | + * user guide available at https://docs.gradle.org/4.5/userguide/java_library_plugin.html |
7 | 7 | */ |
8 | 8 |
|
9 | 9 | // Apply the java-library plugin to add support for Java Library |
10 | 10 | apply plugin: 'java-library' |
| 11 | +apply plugin: 'java' |
| 12 | +apply plugin: 'eclipse' |
| 13 | +apply plugin: 'maven' |
| 14 | +apply plugin: 'maven-publish' |
| 15 | +apply plugin: 'signing' |
11 | 16 | apply plugin: 'jacoco' |
12 | 17 |
|
13 | 18 | // In this section you declare where to find the dependencies of your project |
14 | 19 | repositories { |
15 | 20 | // Use jcenter for resolving your dependencies. |
16 | 21 | // You can declare any Maven/Ivy/file repository here. |
17 | 22 | jcenter() |
| 23 | + mavenCentral() |
| 24 | +} |
| 25 | + |
| 26 | +def platformDependency = "org.apache.httpcomponents:httpclient:4.5.6" |
| 27 | +if ( project.hasProperty("platform") && project.platform == "android" ) { |
| 28 | + platformDependency = "org.apache.httpcomponents:httpclient-android:4.3.5" |
18 | 29 | } |
19 | 30 |
|
20 | 31 | dependencies { |
21 | 32 | // This dependency is exported to consumers, that is to say found on their compile classpath. |
22 | 33 | api 'org.apache.commons:commons-math3:3.6.1' |
23 | 34 |
|
24 | 35 | // This dependency is used internally, and not exposed to consumers on their own compile classpath. |
25 | | - implementation 'com.google.guava:guava:23.0' |
| 36 | + implementation 'com.google.guava:guava:20.0' |
26 | 37 |
|
27 | 38 | // Use JUnit test framework |
28 | 39 | testImplementation 'junit:junit:4.12' |
29 | 40 |
|
30 | | - // Use Apache HttpClient |
31 | | - api 'org.apache.httpcomponents:httpclient:4.5.6' |
| 41 | + api platformDependency |
32 | 42 |
|
33 | 43 | // https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple |
34 | 44 | compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1' |
35 | | - |
36 | 45 | } |
37 | 46 |
|
| 47 | +def pomConfig = { |
| 48 | + licenses { |
| 49 | + license([:]) { |
| 50 | + name "MIT License" |
| 51 | + url "http://opensource.org/licenses/MIT" |
| 52 | + distribution "repo" |
| 53 | + } |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +//Publishing tasks- |
| 58 | +//Maven Central Snapshot: publishSnapshotPublicationToMavenRepository |
| 59 | +//Maven Central Release: publishMavenCentralReleasePublicationToMaven2Repository |
| 60 | +//Bintray Snapshot: publishSnapshotPublicationToMaven3Repository |
| 61 | +//Bintray Release: uploadArchives |
| 62 | + |
| 63 | +publishing { |
| 64 | + |
| 65 | + publications { |
| 66 | + |
| 67 | + maven(MavenPublication) { |
| 68 | + |
| 69 | + groupId 'com.microsoft.graph' |
| 70 | + |
| 71 | + artifactId 'microsoft-graph-core' |
| 72 | + |
| 73 | + version "${mavenMajorVersion}.${mavenMinorVersion}.${mavenPatchVersion}${mavenArtifactSuffix}" |
| 74 | + |
| 75 | + from components.java |
| 76 | + |
| 77 | + artifact sourceJar |
| 78 | + pom.withXml { |
| 79 | + def root = asNode() |
| 80 | + root.appendNode('name', 'Microsoft Graph Core SDK for Java') |
| 81 | + root.appendNode('url', 'https://github.com/microsoftgraph/msgraph-sdk-java-core') |
| 82 | + root.children().last() + pomConfig |
| 83 | + def pomFile = file("${project.buildDir}/libs/microsoft-graph-core.pom") |
| 84 | + writeTo(pomFile) |
| 85 | + } |
| 86 | + |
| 87 | + } |
| 88 | + Snapshot(MavenPublication) { |
| 89 | + customizePom(pom) |
| 90 | + groupId 'com.microsoft.graph' |
| 91 | + artifactId 'microsoft-graph-core' |
| 92 | + version "${mavenMajorVersion}.${mavenMinorVersion}.${mavenPatchVersion}${mavenCentralSnapshotArtifactSuffix}" |
| 93 | + from components.java |
| 94 | + pom.withXml { |
| 95 | + def pomFile = file("${project.buildDir}/generated-pom.xml") |
| 96 | + writeTo(pomFile) |
| 97 | + } |
| 98 | + artifact(sourceJar) { |
| 99 | + classifier = 'sources' |
| 100 | + } |
| 101 | + artifact(javadocJar) { |
| 102 | + classifier = 'javadoc' |
| 103 | + } |
| 104 | + } |
| 105 | + |
| 106 | + mavenCentralRelease(MavenPublication) { |
| 107 | + customizePom(pom) |
| 108 | + groupId 'com.microsoft.graph' |
| 109 | + artifactId 'microsoft-graph-core' |
| 110 | + version "${mavenMajorVersion}.${mavenMinorVersion}.${mavenPatchVersion}" |
| 111 | + from components.java |
| 112 | + pom.withXml { |
| 113 | + def pomFile = file("${project.buildDir}/generated-pom.xml") |
| 114 | + writeTo(pomFile) |
| 115 | + def pomAscFile = signing.sign(pomFile).signatureFiles[0] |
| 116 | + artifact(pomAscFile) { |
| 117 | + classifier = null |
| 118 | + extension = 'pom.asc' |
| 119 | + } |
| 120 | + } |
| 121 | + artifact(sourceJar) { |
| 122 | + classifier = 'sources' |
| 123 | + } |
| 124 | + artifact(javadocJar) { |
| 125 | + classifier = 'javadoc' |
| 126 | + } |
| 127 | + project.tasks.signArchives.signatureFiles.each { |
| 128 | + artifact(it) { |
| 129 | + def matcher = it.file =~ /-(sources|javadoc)\.jar\.asc$/ |
| 130 | + if(matcher.find()){ |
| 131 | + classifier = matcher.group(1) |
| 132 | + } |
| 133 | + else{ |
| 134 | + classifier = null |
| 135 | + } |
| 136 | + extension = 'jar.asc' |
| 137 | + } |
| 138 | + } |
| 139 | + } |
| 140 | + } |
| 141 | + repositories { |
| 142 | + maven { |
| 143 | + url = project.property('mavenCentralSnapshotUrl') |
| 144 | + |
| 145 | + credentials { |
| 146 | + if (project.rootProject.file('local.properties').exists()) { |
| 147 | + |
| 148 | + Properties properties = new Properties() |
| 149 | + |
| 150 | + properties.load(project.rootProject.file('local.properties').newDataInputStream()) |
| 151 | + |
| 152 | + username = properties.getProperty('sonatypeUsername') |
| 153 | + |
| 154 | + password = properties.getProperty('sonatypePassword') |
| 155 | + |
| 156 | + } |
| 157 | + } |
| 158 | + } |
| 159 | + |
| 160 | + maven { |
| 161 | + url = project.property('mavenCentralReleaseUrl') |
| 162 | + |
| 163 | + credentials { |
| 164 | + if (project.rootProject.file('local.properties').exists()) { |
| 165 | + |
| 166 | + Properties properties = new Properties() |
| 167 | + |
| 168 | + properties.load(project.rootProject.file('local.properties').newDataInputStream()) |
| 169 | + |
| 170 | + username = properties.getProperty('sonatypeUsername') |
| 171 | + |
| 172 | + password = properties.getProperty('sonatypePassword') |
| 173 | + |
| 174 | + } |
| 175 | + } |
| 176 | + } |
| 177 | + |
| 178 | + maven { |
| 179 | + url = project.property('mavenBintraySnapshotUrl') |
| 180 | + |
| 181 | + credentials { |
| 182 | + if (project.rootProject.file('local.properties').exists()) { |
| 183 | + |
| 184 | + Properties properties = new Properties() |
| 185 | + |
| 186 | + properties.load(project.rootProject.file('local.properties').newDataInputStream()) |
| 187 | + |
| 188 | + username = (properties.containsKey('bintray.user')) ? properties.getProperty('bintray.user').toLowerCase() : "BINTRAY_USERNAME" |
| 189 | + |
| 190 | + password = properties.getProperty('bintray.apikey') |
| 191 | + |
| 192 | + } |
| 193 | + } |
| 194 | + } |
| 195 | + } |
| 196 | + |
| 197 | +} |
| 198 | + |
| 199 | +task sourceJar(type: Jar) { |
| 200 | + classifier = 'sources' |
| 201 | + from sourceSets.main.allJava |
| 202 | +} |
| 203 | + |
| 204 | +compileJava { |
| 205 | + sourceCompatibility = 1.7 |
| 206 | + targetCompatibility = 1.7 |
| 207 | +} |
| 208 | + |
| 209 | +def getVersionCode() { |
| 210 | + return mavenMajorVersion.toInteger() * 10000 + mavenMinorVersion.toInteger() * 100 + mavenPatchVersion.toInteger() |
| 211 | +} |
| 212 | + |
| 213 | +def getVersionName() { |
| 214 | + return "${mavenMajorVersion}.${mavenMinorVersion}.${mavenPatchVersion}${mavenArtifactSuffix}" |
| 215 | +} |
| 216 | + |
| 217 | +uploadArchives { |
| 218 | + |
| 219 | + def bintrayUsername = "" |
| 220 | + |
| 221 | + def bintrayApikey = "" |
| 222 | + |
| 223 | + if (project.rootProject.file('local.properties').exists()) { |
| 224 | + |
| 225 | + Properties properties = new Properties() |
| 226 | + |
| 227 | + properties.load(project.rootProject.file('local.properties').newDataInputStream()) |
| 228 | + |
| 229 | + bintrayUsername = properties.getProperty('bintray.user') |
| 230 | + |
| 231 | + bintrayApikey = properties.getProperty('bintray.apikey') |
| 232 | + |
| 233 | + } |
| 234 | + |
| 235 | + configuration = configurations.archives |
| 236 | + |
| 237 | + repositories.mavenDeployer { |
| 238 | + |
| 239 | + pom { |
| 240 | + |
| 241 | + setGroupId project.mavenGroupId |
| 242 | + |
| 243 | + setArtifactId project.mavenArtifactId |
| 244 | + |
| 245 | + setVersion getVersionName() |
| 246 | + |
| 247 | + } |
| 248 | + |
| 249 | + repository (url: project.mavenRepoUrl) { |
| 250 | + |
| 251 | + url = url + "/" + getVersionName() |
| 252 | + |
| 253 | + authentication( |
| 254 | + |
| 255 | + // put these values in local file ~/.gradle/gradle.properties |
| 256 | + |
| 257 | + userName: project.hasProperty("bintrayUsername") ? project.bintrayUsername : bintrayUsername, |
| 258 | + |
| 259 | + password: project.hasProperty("bintrayApikey") ? project.bintrayApikey : bintrayApikey |
| 260 | + |
| 261 | + ) |
| 262 | + |
| 263 | + } |
| 264 | + |
| 265 | + } |
| 266 | + |
| 267 | +} |
| 268 | + |
| 269 | +task javadocJar(type: Jar, dependsOn: javadoc) { |
| 270 | + classifier = 'javadoc' |
| 271 | + from javadoc.destinationDir |
| 272 | +} |
| 273 | + |
| 274 | +artifacts { |
| 275 | + archives jar |
| 276 | + archives sourceJar |
| 277 | + archives javadocJar |
| 278 | +} |
| 279 | + |
| 280 | +signing { |
| 281 | + sign configurations.archives |
| 282 | +} |
| 283 | +tasks.withType(Sign)*.enabled = mavenCentralPublishingEnabled.toBoolean() |
| 284 | + |
| 285 | +def customizePom(pom) { |
| 286 | + pom.withXml { |
| 287 | + def root = asNode() |
| 288 | + |
| 289 | + root.dependencies.removeAll { dep -> |
| 290 | + dep.scope == "test" |
| 291 | + } |
| 292 | + |
| 293 | + root.children().last() + { |
| 294 | + resolveStrategy = Closure.DELEGATE_FIRST |
| 295 | + |
| 296 | + description 'Microsoft Graph Core SDK' |
| 297 | + name 'Microsoft Graph Java Core SDK' |
| 298 | + url 'https://github.com/microsoftgraph/msgraph-sdk-java-core' |
| 299 | + organization { |
| 300 | + name 'Microsoft' |
| 301 | + url 'https://github.com/microsoftgraph/msgraph-sdk-java-core' |
| 302 | + } |
| 303 | + issueManagement { |
| 304 | + system 'GitHub' |
| 305 | + url 'https://github.com/microsoftgraph/msgraph-sdk-java-core/issues' |
| 306 | + } |
| 307 | + licenses { |
| 308 | + license { |
| 309 | + name "MIT License" |
| 310 | + url "http://opensource.org/licenses/MIT" |
| 311 | + distribution "repo" |
| 312 | + } |
| 313 | + } |
| 314 | + scm { |
| 315 | + url 'https://github.com/microsoftgraph/msgraph-sdk-java-core' |
| 316 | + connection 'scm:git:git://github.com/microsoftgraph/msgraph-sdk-java-core.git' |
| 317 | + developerConnection 'scm:git:ssh://[email protected]:microsoftgraph/msgraph-sdk-java-core.git' |
| 318 | + } |
| 319 | + developers { |
| 320 | + developer { |
| 321 | + name 'Microsoft' |
| 322 | + } |
| 323 | + } |
| 324 | + } |
| 325 | + } |
| 326 | +} |
| 327 | + |
| 328 | +gradle.taskGraph.whenReady { taskGraph -> |
| 329 | + if (project.rootProject.file('local.properties').exists()) { |
| 330 | + Properties properties = new Properties() |
| 331 | + properties.load(project.rootProject.file('local.properties').newDataInputStream()) |
| 332 | + tasks.withType(Sign)*.enabled = (properties.containsKey('enableSigning')) ? properties.getProperty('enableSigning').toBoolean() : false |
| 333 | + allprojects { ext."signing.keyId" = properties.getProperty('signing.keyId') } |
| 334 | + allprojects { ext."signing.secretKeyRingFile" = properties.getProperty('signing.secretKeyRingFile') } |
| 335 | + allprojects { ext."signing.password" = properties.getProperty('signing.password') } |
| 336 | + } |
| 337 | +} |
| 338 | + |
| 339 | +model { |
| 340 | + tasks.generatePomFileForMavenCentralReleasePublication { |
| 341 | + destination = file("$buildDir/generated-pom.xml") |
| 342 | + } |
| 343 | + tasks.publishMavenCentralReleasePublicationToMavenLocal { |
| 344 | + dependsOn project.tasks.signArchives |
| 345 | + } |
| 346 | + tasks.publishMavenCentralReleasePublicationToMaven2Repository { |
| 347 | + dependsOn project.tasks.signArchives |
| 348 | + } |
| 349 | +} |
0 commit comments