@@ -22,6 +22,7 @@ import com.google.common.collect.Sets
2222
2323plugins {
2424 id ' com.google.api-ads.java-conventions'
25+ id ' maven-publish'
2526 id ' com.google.protobuf' version ' 0.8.15'
2627 id " com.github.hierynomus.license-report" version " 0.15.0"
2728 id ' com.github.johnrengelman.shadow' version ' 6.1.0'
@@ -249,7 +250,8 @@ task copyThirdPartyArtifacts(type: Copy) {
249250shadowJar {
250251 description = " Generates a jar with dependencies"
251252
252- archiveClassifier. set " jar-with-dependencies"
253+ // Removes the default -all classifier.
254+ archiveClassifier = ' '
253255
254256 // Requires that this task is always run and does not build from the cache.
255257 outputs. upToDateWhen { false }
@@ -286,3 +288,90 @@ task testShadowJar {
286288 }
287289 }
288290}
291+
292+ def configurePom (publication , nameToSet , descriptionToSet ) {
293+ publication. pom {
294+ name = nameToSet
295+ description = descriptionToSet
296+ url = ' https://github.com/googleads/google-ads-java'
297+ licenses {
298+ license {
299+ name = ' The Apache License, Version 2.0'
300+ url = ' http://www.apache.org/licenses/LICENSE-2.0.txt'
301+ }
302+ }
303+ scm {
304+ connection = ' scm:git:https://github.com/googleads/google-ads-java'
305+ developerConnection = ' scm:git:https://github.com/googleads/google-ads-java'
306+ url = ' https://github.com/googleads/google-ads-java'
307+ }
308+ developers {
309+ developer {
310+ id = ' josh'
311+ name = ' Josh Radcliff'
312+ email = ' jradcliff@users.noreply.github.com'
313+ organization = ' Google'
314+ organizationUrl = ' https://www.google.com'
315+ }
316+ developer {
317+ id = ' nick'
318+ name = ' Nick Birnie'
319+ email = ' nwbirnie@users.noreply.github.com'
320+ organization = ' Google'
321+ organizationUrl = ' https://www.google.com'
322+ }
323+ developer {
324+ id = ' devin'
325+ name = ' Devin Chasanoff'
326+ email = ' devchas@users.noreply.github.com'
327+ organization = ' Google'
328+ organizationUrl = ' https://www.google.com'
329+ }
330+ }
331+ }
332+ }
333+
334+ final def sonatypeCredentialsConfig = file(System . properties[' user.home' ] + ' /.sonatype-creds' )
335+
336+ publishing {
337+ publications {
338+ shadow(MavenPublication ) { publication ->
339+ project. shadow. component(publication)
340+
341+ groupId = ' com.google.api-ads'
342+ artifactId = ' google-ads-shadowjar'
343+ version = ' 0.0.1-alpha'
344+
345+ configurePom(publication,
346+ " Google Ads API client library for java - shadow jar" ,
347+ " Provides a jar with all dependencies" )
348+ }
349+ }
350+
351+ repositories {
352+ maven {
353+ url ' https://oss.sonatype.org/service/local/staging/deploy/maven2'
354+ name = " sonatype"
355+
356+ if (sonatypeCredentialsConfig. exists()) {
357+ def props = new Properties ()
358+ sonatypeCredentialsConfig. withInputStream { props. load(it) }
359+ credentials {
360+ username props[' username' ]
361+ password props[' password' ]
362+ }
363+ }
364+ }
365+ }
366+ }
367+
368+ // Provide a helpful error message for missing sonatype credentials.
369+ tasks. findAll {
370+ if (it. name. matches(" publish.+ToSonatypeRepository" )) {
371+ it. doFirst {
372+ if (! sonatypeCredentialsConfig. exists()) {
373+ throw new GradleException (" Unable to load Sonatype credentials from ${ sonatypeCredentialsConfig} ." )
374+ }
375+ }
376+ }
377+ }
0 commit comments