Skip to content

Commit 5a8ffce

Browse files
authored
tag 0.11.0 (#30)
* update docs * release 0.11.0
1 parent 3028220 commit 5a8ffce

File tree

3 files changed

+58
-64
lines changed

3 files changed

+58
-64
lines changed

CHANGELOG.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Next version (unreleased)
22

3+
# Version 0.11.0
4+
_2024-11-25_
5+
36

47
## Configurable R8 version
58

@@ -17,6 +20,7 @@ repositories {
1720
gr8 {
1821
create("default") {
1922
r8Version("8.8.19")
23+
//...
2024
}
2125
}
2226
```
@@ -27,13 +31,14 @@ Gr8 can also download a R8 jar from a git sha1:
2731
gr8 {
2832
create("default") {
2933
r8Version("887704078a06fc0090e7772c921a30602bf1a49f")
34+
//...
3035
}
3136
}
3237
```
3338

3439
## [BREAKING] Artifact transform
3540

36-
Gr8 now includes an [artifact transform](https://docs.gradle.org/current/userguide/artifact_transforms.html) to filter the input jars:
41+
Gr8 now uses an [artifact transform](https://docs.gradle.org/current/userguide/artifact_transforms.html) to filter the input jars:
3742

3843
```kotlin
3944
gr8 {
@@ -47,9 +52,9 @@ As a consequence, `Gr8Configurator.configuration(String)` and `Gr8Configurator.c
4752
gr8 {
4853
create("default") {
4954
// Replace
50-
configuration("runtimeClasspath")
55+
configuration("shadowedDependencies")
5156
// With
52-
addProgramJarsFrom(configurations.getByName("runtimeClasspath"))
57+
addProgramJarsFrom(configurations.getByName("shadowedDependencies"))
5358

5459
// Replace
5560
stripGradleApi(true)
@@ -68,5 +73,4 @@ gr8 {
6873
addClassPathJarsFrom(compileOnlyDependenciesForGr8)
6974
}
7075
}
71-
7276
```

README.md

Lines changed: 48 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,8 @@ dependencies {
3232
* Create a separate configuration to resolve compileOnly dependencies.
3333
* You can skip this if you have no compileOnly dependencies.
3434
*/
35-
val compileOnlyDependenciesForGr8: Configuration = configurations.create("compileOnlyDependenciesForGr8") {
36-
/**
37-
* Only get the jars needed for compilation, no need to resolve implementations
38-
*/
39-
attributes {
40-
attribute(Usage.USAGE_ATTRIBUTE, project.objects.named<Usage>(Usage.JAVA_API))
41-
}
42-
}
43-
compileOnlyDependenciesForGr8.extendsFrom(configurations.getByName("compileOnly"))
35+
val compileOnlyDependencies: Configuration = configurations.create("compileOnlyDependencies")
36+
compileOnlyDependencies.extendsFrom(configurations.getByName("compileOnly"))
4437

4538
gr8 {
4639
val shadowedJar = create("gr8") {
@@ -49,7 +42,7 @@ gr8 {
4942
addProgramJarsFrom(tasks.getByName("jar"))
5043
// classpath jars are only used by R8 for analysis but are not included in the
5144
// final shadowed jar.
52-
addClassPathJarsFrom(compileOnlyDependenciesForGr8)
45+
addClassPathJarsFrom(compileOnlyDependencies)
5346
proguardFile("rules.pro")
5447

5548
// Use a version from https://storage.googleapis.com/r8-releases/raw
@@ -60,13 +53,6 @@ gr8 {
6053
r8Version("887704078a06fc0090e7772c921a30602bf1a49f")
6154
// Or leave it to the default version
6255
}
63-
64-
// Optional: replace the regular jar with the shadowed one in the publication
65-
replaceOutgoingJar(shadowedJar)
66-
67-
// Or if you prefer the shadowed jar to be a separate variant in the default publication
68-
// The variant will have `org.gradle.dependency.bundling = shadowed`
69-
addShadowedVariant(shadowedJar)
7056
}
7157
```
7258

@@ -86,62 +72,66 @@ Then customize your proguard rules. The below is a non-exhaustive example. If yo
8672
-keepattributes Signature,Exceptions,*Annotation*,InnerClasses,PermittedSubclasses,EnclosingMethod,Deprecated,SourceFile,LineNumberTable
8773
```
8874

89-
## Using Gr8 for Gradle plugins
90-
91-
92-
The `java-gradle-plugin` automatically adds `api(gradleApi())` to your dependencies, exposing `gradleApi()` in your runtime classpath by default.
75+
## Using Gr8 for Gradle plugins
9376

94-
`gradleApi()` must not be embedded in your shadowed plugin as those classes are provided by the Gradle instance running your plugin.
77+
Using Gr8 to shadow dependencies in Gradle plugin is a typical use case but requires extra care because:
9578

96-
What's more, contains `gradleApi()` newer symbols that might not be available in older versions of Gradle your plugin needs to support.
79+
* The `java-gradle-plugin` automatically adds `api(gradleApi())` to your dependencies but `gradleApi()` shouldn't be shadowed.
80+
* `gradleApi()` is a [multi-release jar](https://docs.oracle.com/javase/10/docs/specs/jar/jar.html#multi-release-jar-files) file that [R8 doesn't support](https://issuetracker.google.com/u/1/issues/380805015).
81+
* Since the plugins are published, the shadowed dependencies must not be exposed in the .pom/.module files.
9782

98-
To workaround this, you can use the [Nokee relocated artifacts](https://docs.nokee.dev/manual/gradle-plugin-development-plugin.html) and `removeGradleApiFromApi()`:
83+
To work around this, you can use, `removeGradleApiFromApi()`, `registerTransform()` and custom configurations:
9984

10085
```kotlin
101-
dependencies {
102-
compileOnly("dev.gradleplugins:gradle-api:7.6")
103-
}
104-
val compileOnlyDependenciesForGr8: Configuration = configurations.create("compileOnlyDependenciesForGr8") {
86+
val shadowedDependencies = configurations.create("shadowedDependencies")
87+
88+
val compileOnlyDependencies: Configuration = configurations.create("compileOnlyDependencies") {
10589
attributes {
10690
attribute(Usage.USAGE_ATTRIBUTE, project.objects.named<Usage>(Usage.JAVA_API))
10791
}
108-
}
109-
110-
compileOnlyDependenciesForGr8.extendsFrom(configurations.getByName("compileOnly"))
111-
112-
gr8 {
113-
create("default") {
114-
addClassPathJarsFrom(compileOnlyDependenciesForGr8)
115-
// ...
116-
}
117-
removeGradleApiFromApi()
118-
}
119-
```
120-
121-
At the time of writing [R8 doesn't support multi-release jars](https://issuetracker.google.com/u/1/issues/380805015) and you might bump into this issue:
122-
123-
```
124-
Caused by: com.android.tools.r8.errors.CompilationError: Class content provided for type descriptor
125-
org.gradle.internal.impldep.META-INF.versions.15.org.bouncycastle.jcajce.provider.asymmetric.edec.SignatureSpi
126-
actually defines class org.gradle.internal.impldep.org.bouncycastle.jcajce.provider.asymmetric.edec.SignatureSpi
127-
```
128-
129-
To workaround, Gr8 provides an artifact transform that can remove the multi-release classes. To do so, use `registerFilterTransform`:
130-
131-
```kotlin
132-
val compileOnlyDependenciesForGr8: Configuration = configurations.create("compileOnlyDependenciesForGr8") {
13392
attributes {
13493
attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, FilterTransform.artifactType)
13594
}
136-
attributes {
137-
attribute(Usage.USAGE_ATTRIBUTE, project.objects.named<Usage>(Usage.JAVA_API))
138-
}
95+
}
96+
compileOnlyDependencies.extendsFrom(configurations.getByName("compileOnly"))
97+
98+
dependencies {
99+
add(shadowedDependencies.name, "com.squareup.okhttp3:okhttp:4.9.0")
100+
add(compileOnlyDependencies.name, gradleApi())
101+
// More dependencies here
139102
}
140103
compileOnlyDependenciesForGr8.extendsFrom(configurations.getByName("compileOnly"))
141104

142-
gr8 {
143-
registerFilterTransform(listOf(".*/impldep/META-INF/versions/.*"))
105+
if (shadow) {
106+
gr8 {
107+
create("default") {
108+
val shadowedJar = create("default") {
109+
addProgramJarsFrom(shadowedDependencies)
110+
addProgramJarsFrom(tasks.getByName("jar"))
111+
112+
proguardFile("rules.pro")
113+
registerFilterTransform(listOf(".*/impldep/META-INF/versions/.*"))
114+
}
115+
116+
removeGradleApiFromApi()
117+
118+
// Optional: replace the regular jar with the shadowed one in the publication
119+
replaceOutgoingJar(shadowedJar)
120+
121+
// Or if you prefer the shadowed jar to be a separate variant in the default publication
122+
// The variant will have `org.gradle.dependency.bundling = shadowed`
123+
addShadowedVariant(shadowedJar)
124+
125+
// Allow to compile the module without exposing the shadowedDependencies downstream
126+
configurations.getByName("compileOnly").extendsFrom(shadowedDependencies)
127+
configurations.getByName("compileOnly").extendsFrom(compileOnlyDependencies)
128+
configurations.getByName("testImplementation").extendsFrom(shadowedDependencies)
129+
}
130+
}
131+
} else {
132+
configurations.named("implementation").extendsFrom(shadowedDependencies)
144133
}
134+
145135
```
146136

147137
## Kotlin interop

librarian.root.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ kdoc.olderVersions=
66
sonatype.backend=Default
77

88
pom.groupId=com.gradleup
9-
pom.version=0.11.0-SNAPSHOT
9+
pom.version=0.11.0
1010
pom.description=Gradle + R8 = <3
1111
pom.vcsUrl=https://github.com/GradleUp/gr8
1212
pom.developer=gr8 authors
1313
pom.license=MIT License
1414

1515
gcs.bucket=gradleup
16-
gcs.prefix=m2
16+
gcs.prefix=m2

0 commit comments

Comments
 (0)