@@ -114,19 +114,10 @@ task generateLicenses(type: nl.javadude.gradle.plugins.license.DownloadLicenses)
114114 description = " Copies the license report into the third_party directory"
115115
116116 includeProjectDependencies = true
117+
117118 // Works around issue where the plugin looks at the deprecated 'compile'
118119 // configuration by default.
119120 dependencyConfiguration = ' runtimeClasspath'
120-
121- // Defines variables for the expected output files.
122- def outputDirectory = tasks. downloadLicenses. outputs. files. files. find()
123- def outputFilePattern = outputDirectory. absoluteFile. path + File . separator + " dependency-license."
124- def licenses = [" html" , " json" , " xml" ]. collect({ file(outputFilePattern + it) })
125-
126- // Exports the output file names for use elsewhere.
127- ext {
128- licenseFiles = licenses
129- }
130121}
131122
132123task verifyLicenses () {
@@ -135,7 +126,7 @@ task verifyLicenses() {
135126
136127 doLast {
137128 // Reads the dependency-license.json file generated by generateLicenses.
138- def inputFile = tasks. generateLicenses. licenseFiles . find { it. path. endsWith(" .json" ) }
129+ def inputFile = tasks. generateLicenses. outputs . files . files . find { it. path. endsWith(" .json" ) }
139130 def json = new JsonSlurper (). parseText(inputFile. text)
140131 // Gets all the licenses except those for ourselves (which aren't set yet).
141132 def licenses = json
@@ -183,7 +174,10 @@ task copyLicenses(type: Copy) {
183174 dependsOn ' generateLicenses'
184175 mustRunAfter ' createThirdPartyDirectory'
185176
186- from tasks. generateLicenses. licenseFiles
177+ def inputFiles = tasks. generateLicenses. outputs. files. asFileTree. files
178+ .findAll { it. path. contains " dependency-license" }
179+
180+ from inputFiles
187181 into tasks. generateThirdPartyDirectory. thirdPartyDir
188182 // Rename files to LICENSES.*
189183 eachFile {
@@ -197,10 +191,10 @@ task copyLicenses(type: Copy) {
197191 // Fails the build if we didn't copy everything. Gradle will fail silently if
198192 // it cannot copy one of the inputs which is dangerous when you're dealing
199193 // with legal obligations.
200- if (tasks . generateLicenses . licenseFiles . size() != inputs. sourceFiles. size()) {
194+ if (inputFiles . size() != inputs. sourceFiles. size()) {
201195 throw new GradleException (
202196 " Failed to locate files to copy from. Expected: "
203- + tasks . generateLicenses . licenseFiles
197+ + inputFiles
204198 + " but was: " + inputs. sourceFiles. toList())
205199 }
206200 }
@@ -275,15 +269,12 @@ shadowJar {
275269 // Removes the default -all classifier.
276270 archiveClassifier = ' '
277271
278- // Requires that this task is always run and does not build from the cache.
279- outputs. upToDateWhen { false }
280-
281272 // Updates the META-INF/services directory with the services from dependencies
282273 mergeServiceFiles()
283274
284275 // Includes the license report with the shadow jar.
285276 dependsOn ' generateLicenses'
286- from tasks. generateLicenses. licenseFiles
277+ from tasks. generateLicenses. outputs
287278
288279 finalizedBy ' testShadowJar'
289280}
@@ -296,17 +287,25 @@ task testShadowJar {
296287
297288 doLast {
298289 javaexec {
299- mainClass = " com.google.ads.googleads.lib.SmokeTest"
290+ // Runs the JUnit main method.
291+ mainClass = " org.junit.runner.JUnitCore"
292+
293+ // Passes the class name of the test to run.
294+ args " com.google.ads.googleads.lib.SmokeTest"
295+
300296 // Uses a special configuration to run the smoke tests. Allows us to
301297 // replace the google-ads dependency with the shaded artifact so we can
302298 // test it. Otherwise we'd just run end up running the smoke tests on
303299 // the normal jar twice.
304300 classpath = project. configurations. shadeTest +
305- // Uses the compiler output directly, rather than getting the
306- // dependencies from the configuration (since this would include
307- // the artifact we're trying to ignore).
308- files(sourceSets. functionalTest. output. classesDirs. files,
309- shadowJar. outputs. files)
301+ // Uses the compiler output directly, rather than getting the
302+ // dependencies from the configuration (since this would include
303+ // the artifact we're trying to ignore).
304+ files(sourceSets. functionalTest. output. classesDirs. files,
305+ shadowJar. outputs. files)
306+
307+ // Allows the smoke tests to pass unless we're publishing to sonatype.
308+ ignoreExitValue = ! gradle. taskGraph. hasTask(" publishMavenPublicationToSonatypeRepository" )
310309 }
311310 }
312311}
@@ -397,6 +396,16 @@ signing {
397396 sign publishing. publications. shadow
398397}
399398
399+ // Disables signing tasks except on sonatype deploy. Avoids failing build for
400+ // users without GPG configured.
401+ gradle. taskGraph. whenReady {
402+ if (gradle. taskGraph. allTasks
403+ .findAll { it. name. matches(" publish.+ToSonatypeRepository" ) }
404+ .isEmpty()) {
405+ tasks. findByName(" signShadowPublication" ). enabled = false
406+ }
407+ }
408+
400409// Provide a helpful error message for missing sonatype credentials.
401410tasks. findAll {
402411 if (it. name. matches(" publish.+ToSonatypeRepository" )) {
0 commit comments