@@ -88,10 +88,26 @@ task generateThirdPartyDirectory() {
8888 description = " Generates the third_party directory (containing dependencies" +
8989 " + licenses)"
9090
91+ ext {
92+ thirdPartyDir = file ' ../third_party'
93+ }
94+ dependsOn ' createThirdPartyDirectory'
9195 dependsOn ' copyThirdPartyArtifacts'
9296 dependsOn ' copyLicenses'
9397}
9498
99+ task createThirdPartyDirectory () {
100+ doLast {
101+ def thirdPartyDir = tasks. generateThirdPartyDirectory. thirdPartyDir
102+ if (thirdPartyDir. exists() && ! thirdPartyDir. deleteDir()) {
103+ throw new GradleException (' third_party exists but failed to delete' )
104+ }
105+ if (! thirdPartyDir. mkdir()) {
106+ throw new GradleException (" Failed to create third_party directory" )
107+ }
108+ }
109+ }
110+
95111task generateLicenses (type : nl.javadude.gradle.plugins.license.DownloadLicenses ) {
96112 description = " Copies the license report into the third_party directory"
97113
@@ -163,9 +179,10 @@ Googlers, there is a company policy for this available internally.""")
163179task copyLicenses (type : Copy ) {
164180 description = " Copies licenses from build directory to third_party"
165181 dependsOn ' generateLicenses'
182+ mustRunAfter ' createThirdPartyDirectory'
166183
167184 from tasks. generateLicenses. licenseFiles
168- into ' ../third_party '
185+ into tasks . generateThirdPartyDirectory . thirdPartyDir
169186 // Rename files to LICENSES.*
170187 eachFile {
171188 if (! path. contains(" dependency-license" )) {
@@ -180,27 +197,21 @@ task copyLicenses(type: Copy) {
180197 // with legal obligations.
181198 if (tasks. generateLicenses. licenseFiles. size() != inputs. sourceFiles. size()) {
182199 throw new GradleException (
183- " Failed to locate files to copy from. Expected: "
184- + tasks. generateLicenses. licenseFiles
185- + " but was: " + inputs. sourceFiles. toList())
200+ " Failed to locate files to copy from. Expected: "
201+ + tasks. generateLicenses. licenseFiles
202+ + " but was: " + inputs. sourceFiles. toList())
186203 }
187204 }
188205}
189206
190207task copyThirdPartyArtifacts (type : Copy ) {
191208 description = " Copies the sources and binaries of dependencies to third_party"
209+ mustRunAfter ' createThirdPartyDirectory'
192210
193211 // Requires that this task is always run since it's hard to detect when the
194212 // dependencies have changed.
195213 outputs. upToDateWhen { false }
196214
197- def thirdPartyDir = file ' ../third_party'
198- if (thirdPartyDir. exists() && ! thirdPartyDir. deleteDir()) {
199- throw new GradleException (' third_party exists but failed to delete' )
200- }
201- if (! thirdPartyDir. mkdir()) {
202- throw new GradleException (" Failed to create third_party directory" )
203- }
204215 def dependencies = configurations. runtimeClasspath
205216 .resolvedConfiguration
206217 .resolvedArtifacts
@@ -224,7 +235,7 @@ task copyThirdPartyArtifacts(type: Copy) {
224235 " dependencies, ${ files.size()} < ${ dependencies.size()} " )
225236 }
226237 from files
227- into thirdPartyDir
238+ into tasks . generateThirdPartyDirectory . thirdPartyDir
228239 doLast {
229240 logger. info(' Resolved third party dependencies' )
230241 files. each {
0 commit comments