Skip to content

Commit 62c3d1b

Browse files
authored
Move shadow jar to its own project. (#527)
1 parent 587b604 commit 62c3d1b

5 files changed

Lines changed: 92 additions & 96 deletions

File tree

.gitignore

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,4 @@ google-ads/*/buildNumber.properties
4848
# Gradle build output
4949
.gradle/
5050
buildSrc/.gradle/
51-
buildSrc/build/
52-
google-ads-annotation-processing/build/
53-
google-ads-examples/build/
54-
google-ads-migration-examples/build/
55-
google-ads/build/
51+
*/build

google-ads-shadowjar/build.gradle

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
plugins {
2+
id 'com.google.api-ads.java-conventions'
3+
id 'com.github.johnrengelman.shadow' version '6.1.0'
4+
}
5+
6+
configurations {
7+
shadeTest
8+
functionalTestImplementation.extendsFrom testImplementation
9+
functionalTestRuntimeOnly.extendsFrom testRuntimeOnly
10+
}
11+
12+
dependencies {
13+
implementation project(":google-ads")
14+
shadeTest 'junit:junit:4.13.1'
15+
}
16+
17+
// Provides functional tests that can be bypassed (e.g. when running
18+
// without an ads.properties file).
19+
sourceSets {
20+
functionalTest {
21+
java {
22+
srcDir 'src/test/functional/java'
23+
}
24+
resources {
25+
srcDir 'src/test/functional/resources'
26+
}
27+
compileClasspath += sourceSets.main.output
28+
runtimeClasspath += sourceSets.main.output
29+
}
30+
}
31+
32+
task functionalTest(type: Test) {
33+
description = "Runs functional tests"
34+
testClassesDirs = sourceSets.functionalTest.output.classesDirs
35+
classpath = sourceSets.functionalTest.runtimeClasspath
36+
}
37+
38+
shadowJar {
39+
description = "Generates a jar with dependencies"
40+
41+
// Removes the default -all classifier.
42+
archiveClassifier = ''
43+
44+
// Updates the META-INF/services directory with the services from dependencies
45+
mergeServiceFiles()
46+
47+
finalizedBy 'testShadowJar'
48+
}
49+
50+
task testShadowJar {
51+
description = "Executes functional tests for shadow jar"
52+
53+
dependsOn shadowJar
54+
dependsOn functionalTestClasses
55+
56+
doLast {
57+
javaexec {
58+
// Runs the JUnit main method.
59+
mainClass = "org.junit.runner.JUnitCore"
60+
61+
// Passes the class name of the test to run.
62+
args "com.google.ads.googleads.lib.SmokeTest"
63+
64+
// Uses a special configuration to run the smoke tests. Allows us to
65+
// replace the google-ads dependency with the shaded artifact so we can
66+
// test it. Otherwise we'd just run end up running the smoke tests on
67+
// the normal jar twice.
68+
classpath = project.configurations.shadeTest +
69+
// Uses the compiler output directly, rather than getting the
70+
// dependencies from the configuration (since this would include
71+
// the artifact we're trying to ignore).
72+
files(sourceSets.functionalTest.output.classesDirs.files,
73+
shadowJar.outputs.files)
74+
75+
// Allows the smoke tests to pass unless we're publishing to sonatype.
76+
ignoreExitValue = !project.properties.containsKey("release")
77+
}
78+
}
79+
}
80+
81+
publishing {
82+
publications {
83+
maven(MavenPublication) { publication ->
84+
configurePom(publication,
85+
"Google Ads API client library for java - shadow jar",
86+
"Provides a jar with all dependencies")
87+
}
88+
}
89+
}

google-ads/src/test/functional/java/com/google/ads/googleads/lib/SmokeTest.java renamed to google-ads-shadowjar/src/test/functional/java/com/google/ads/googleads/lib/SmokeTest.java

File renamed without changes.

google-ads/build.gradle

Lines changed: 0 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ plugins {
2424
id 'com.google.api-ads.java-conventions'
2525
id 'com.google.protobuf' version '0.8.15'
2626
id "com.github.hierynomus.license-report" version "0.15.0"
27-
id 'com.github.johnrengelman.shadow' version '6.1.0'
2827
}
2928

3029
description = 'Google Ads API client library for Java'
@@ -35,18 +34,6 @@ sourceSets {
3534
srcDir 'src/test/resources/protos/'
3635
}
3736
}
38-
// Provides functional tests that can be bypassed (e.g. when running
39-
// without an ads.properties file).
40-
functionalTest {
41-
java {
42-
srcDir 'src/test/functional/java'
43-
}
44-
resources {
45-
srcDir 'src/test/functional/resources'
46-
}
47-
compileClasspath += sourceSets.main.output
48-
runtimeClasspath += sourceSets.main.output
49-
}
5037
}
5138
sourceSets.test.java.srcDir new File(buildDir, 'generated/source/proto/test')
5239

@@ -56,12 +43,6 @@ protobuf {
5643
}
5744
}
5845

59-
configurations {
60-
shadeTest
61-
functionalTestImplementation.extendsFrom testImplementation
62-
functionalTestRuntimeOnly.extendsFrom testRuntimeOnly
63-
}
64-
6546
dependencies {
6647
implementation 'io.netty:netty-tcnative-boringssl-static:2.0.26.Final'
6748
implementation 'org.slf4j:slf4j-api:1.7.25'
@@ -76,14 +57,8 @@ dependencies {
7657
testImplementation 'com.google.truth:truth:0.27'
7758
implementation 'com.google.auto.value:auto-value-annotations:1.7.3'
7859
testImplementation 'com.google.auto.value:auto-value-annotations:1.7.3'
79-
shadeTest 'junit:junit:4.13.1'
8060
}
8161

82-
task functionalTest(type: Test) {
83-
description = "Runs functional tests"
84-
testClassesDirs = sourceSets.functionalTest.output.classesDirs
85-
classpath = sourceSets.functionalTest.runtimeClasspath
86-
}
8762

8863
// --------------------- third_party directory generation ----------------------
8964

@@ -269,78 +244,12 @@ task copyThirdPartyBinaries(type: Copy) {
269244
into tasks.generateThirdPartyDirectory.thirdPartyDir
270245
}
271246

272-
// ------------------------------ Shadow jar -----------------------------------
273-
274-
shadowJar {
275-
description = "Generates a jar with dependencies"
276-
277-
// Removes the default -all classifier.
278-
archiveClassifier = ''
279-
280-
// Updates the META-INF/services directory with the services from dependencies
281-
mergeServiceFiles()
282-
283-
// Includes the license report with the shadow jar.
284-
dependsOn 'generateLicenses'
285-
from tasks.generateLicenses.outputs
286-
287-
finalizedBy 'testShadowJar'
288-
}
289-
290-
task testShadowJar {
291-
description = "Executes functional tests for shadow jar"
292-
293-
dependsOn shadowJar
294-
dependsOn functionalTestClasses
295-
296-
doLast {
297-
javaexec {
298-
// Runs the JUnit main method.
299-
mainClass = "org.junit.runner.JUnitCore"
300-
301-
// Passes the class name of the test to run.
302-
args "com.google.ads.googleads.lib.SmokeTest"
303-
304-
// Uses a special configuration to run the smoke tests. Allows us to
305-
// replace the google-ads dependency with the shaded artifact so we can
306-
// test it. Otherwise we'd just run end up running the smoke tests on
307-
// the normal jar twice.
308-
classpath = project.configurations.shadeTest +
309-
// Uses the compiler output directly, rather than getting the
310-
// dependencies from the configuration (since this would include
311-
// the artifact we're trying to ignore).
312-
files(sourceSets.functionalTest.output.classesDirs.files,
313-
shadowJar.outputs.files)
314-
315-
// Allows the smoke tests to pass unless we're publishing to sonatype.
316-
ignoreExitValue = !gradle.taskGraph.hasTask("publishMavenPublicationToSonatypeRepository")
317-
}
318-
}
319-
}
320-
321247
publishing {
322248
publications {
323249
maven(MavenPublication) { publication ->
324250
configurePom(publication,
325251
"Google Ads API client library for Java - main library",
326252
"Main library for the Google Ads API client library for Java")
327253
}
328-
shadow(MavenPublication) { publication ->
329-
project.shadow.component(publication)
330-
// Publishes the javadoc + sources with the shadowjar.
331-
configurations.javadocElements.artifacts.each {
332-
artifact it
333-
}
334-
configurations.sourcesElements.artifacts.each {
335-
artifact it
336-
}
337-
338-
groupId = 'com.google.api-ads'
339-
artifactId = 'google-ads-shadowjar'
340-
341-
configurePom(publication,
342-
"Google Ads API client library for java - shadow jar",
343-
"Provides a jar with all dependencies")
344-
}
345254
}
346255
}

settings.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ rootProject.name = 'google-ads-parent'
2121

2222
include ':google-ads-annotation-processing'
2323
include ':google-ads'
24+
include ':google-ads-shadowjar'
2425

2526
// Enables the examples project only if we're not deploying to Sonatype.
2627
if (!startParameter.projectProperties.containsKey("release")) {
2728
include ':google-ads-examples'
2829
include ':google-ads-migration-examples'
2930
}
31+

0 commit comments

Comments
 (0)