Skip to content

Commit d0f85b2

Browse files
authored
Merge pull request #7 from microsoftgraph/publish-script
Update gradle script with code to publish
2 parents cd70c24 + eda6444 commit d0f85b2

File tree

2 files changed

+363
-5
lines changed

2 files changed

+363
-5
lines changed

build.gradle

Lines changed: 317 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,347 @@
33
*
44
* This generated file contains a sample Java Library project to get you started.
55
* 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
77
*/
88

99
// Apply the java-library plugin to add support for Java Library
1010
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'
1116
apply plugin: 'jacoco'
1217

1318
// In this section you declare where to find the dependencies of your project
1419
repositories {
1520
// Use jcenter for resolving your dependencies.
1621
// You can declare any Maven/Ivy/file repository here.
1722
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"
1829
}
1930

2031
dependencies {
2132
// This dependency is exported to consumers, that is to say found on their compile classpath.
2233
api 'org.apache.commons:commons-math3:3.6.1'
2334

2435
// 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'
2637

2738
// Use JUnit test framework
2839
testImplementation 'junit:junit:4.12'
2940

30-
// Use Apache HttpClient
31-
api 'org.apache.httpcomponents:httpclient:4.5.6'
41+
api platformDependency
3242

3343
// https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple
3444
compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1'
35-
3645
}
3746

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+
}

gradle.properties

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Project-wide Gradle settings.
2+
3+
# IDE users:
4+
# Settings specified in this file will override any Gradle settings
5+
# configured through the IDE.
6+
7+
# For more details on how to configure your build environment visit
8+
# http://www.gradle.org/docs/current/userguide/build_environment.html
9+
10+
# Specifies the JVM arguments used for the daemon process.
11+
# The setting is particularly useful for tweaking memory settings.
12+
# Default value: -Xmx10248m -XX:MaxPermSize=256m
13+
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14+
15+
# When configured, Gradle will run in incubating parallel mode.
16+
# This option should only be used with decoupled projects. More details, visit
17+
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18+
# org.gradle.parallel=true
19+
20+
# The size of the library demands a large amount of RAM to build. Increase as necessary if you get GC errors
21+
## linux requires 10G, OSX requires 11G
22+
org.gradle.jvmargs=-XX:MaxPermSize=512m -Xmx2g
23+
24+
mavenRepoUrl = https://api.bintray.com/content/microsoftgraph/Maven/microsoft-graph
25+
mavenBintraySnapshotUrl = http://oss.jfrog.org/artifactory/oss-snapshot-local
26+
mavenGroupId = com.microsoft.graph
27+
mavenArtifactId = microsoft-graph-core
28+
mavenMajorVersion = 0
29+
mavenMinorVersion = 1
30+
mavenPatchVersion = 0
31+
mavenArtifactSuffix =
32+
nightliesUrl = http://dl.bintray.com/MicrosoftGraph/Maven
33+
34+
#These values are used to run functional tests
35+
#If you wish to run the functional tests, edit the gradle.properties
36+
#file in your user directory instead of adding them here.
37+
#ex: C:\Users\username\.gradle\gradle.properties
38+
ClientId="CLIENT_ID"
39+
Username="USERNAME"
40+
Password="PASSWORD"
41+
42+
#enable mavenCentralPublishingEnabled to publish to maven central
43+
mavenCentralSnapshotUrl=https://oss.sonatype.org/content/repositories/snapshots
44+
mavenCentralReleaseUrl=https://oss.sonatype.org/service/local/staging/deploy/maven2
45+
mavenCentralSnapshotArtifactSuffix = -SNAPSHOT
46+
mavenCentralPublishingEnabled=false

0 commit comments

Comments
 (0)