Skip to content

Commit

Permalink
Copy Kotlin variant metadata from alternative source (fixes #442)
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-manes committed Nov 7, 2020
1 parent 4f2d15c commit 6c4a1e8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
14 changes: 4 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ allprojects {
}
```

The current version is known to work with Gradle versions up to 5.6.

## Tasks

### `dependencyUpdates`
Expand Down Expand Up @@ -326,7 +324,7 @@ Gradle updates:
- Gradle: [4.6 -> 4.7 -> 4.8-rc-2]
```

Json report
#### Json report
```json
{
"current": {
Expand Down Expand Up @@ -440,7 +438,7 @@ Json report
}
```

XML report
#### XML report
```xml
<response>
<count>8</count>
Expand Down Expand Up @@ -550,12 +548,8 @@ XML report
</response>
```

HTML report

```
The HTML report provides sections for current, outdated, exceeded and unresolved dependencies.
```

#### HTML report
[<img src="examples/html-report.png" width="400"/>](examples/html-report.png)

#### <a name="custom_report_format"></a>Custom report format
If you need to create a report in a custom format, you can set the `dependencyUpdates` tasks's `outputFormatter` property to a Closure. The closure will be called with a single argument that is an instance of [com.github.benmanes.gradle.versions.reporter.result.Result](src/main/groovy/com/github/benmanes/gradle/versions/reporter/result/Result.groovy).
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ apply plugin: 'nexus'
apply plugin: 'codenarc'

group = 'com.github.ben-manes'
version = '0.34.0'
version = '0.35.0'

sourceCompatibility = '1.8'

Expand Down
Binary file added examples/html-report.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,13 @@ class Resolver {
}.minus(configuration.dependencies)

// Adds the Kotlin 1.2.x legacy metadata to assist in variant selection
Configuration metadata = project.configurations.findByName("commonMainMetadataElements")
if (metadata != null) {
Configuration metadata = project.configurations.findByName('commonMainMetadataElements')
if (metadata == null) {
Configuration compile = project.configurations.findByName("compile")
if (compile != null) {
addAttributes(copy, compile, { String key -> key.contains('kotlin') })
}
} else {
addAttributes(copy, metadata)
}

Expand Down Expand Up @@ -200,11 +205,14 @@ class Resolver {
}

/** Adds the attributes from the source to the target. */
private void addAttributes(HasConfigurableAttributes target, HasConfigurableAttributes source) {
private void addAttributes(HasConfigurableAttributes target,
HasConfigurableAttributes source, Closure filter = { String key -> true }) {
target.attributes { container ->
for (def key : source.attributes.keySet()) {
def value = source.attributes.getAttribute(key)
container.attribute(key, value)
if (filter.call(key.name)) {
def value = source.attributes.getAttribute(key)
container.attribute(key, value)
}
}
}
}
Expand Down

0 comments on commit 6c4a1e8

Please sign in to comment.