Skip to content

Commit

Permalink
* Fix compatibility with Gradle 7.6.x (issue #28)
Browse files Browse the repository at this point in the history
  • Loading branch information
saudet committed Dec 21, 2022
1 parent d7d57e8 commit 9098dcd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gradle-javacpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ env:
STAGING_REPOSITORY: ${{ secrets.STAGING_REPOSITORY }}
jobs:
linux-x86_64:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
container: centos:7
steps:
- uses: bytedeco/javacpp-presets/.github/actions/deploy-centos@actions
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

* Fix compatibility with Gradle 7.6.x ([issue #28](https://github.com/bytedeco/gradle-javacpp/issues/28))

### November 2, 2022 version 1.5.8
* Remove lambda expressions since Gradle dislikes them ([issue #23](https://github.com/bytedeco/gradle-javacpp/issues/23))
* Update instructions to integrate `BuildTask` with Android Studio ([issue #22](https://github.com/bytedeco/gradle-javacpp/issues/22))
Expand Down
43 changes: 23 additions & 20 deletions src/main/java/org/bytedeco/gradle/javacpp/PlatformRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,31 +70,34 @@ class PlatformRule implements ComponentMetadataRule {
while (i.hasNext()) {
DirectDependencyMetadata d = i.next();
String classifier = null;
// This only works starting with Gradle 6.3:
// List<DependencyArtifact> as = d.getArtifactSelectors();
// if (as != null && as.size() > 0) {
// classifier = as.get(0).getClassifier();
// }
// So try to get the classifier some other way...
try {
if (d instanceof AbstractDependencyMetadataAdapter) {
Method getMetadata = AbstractDependencyMetadataAdapter.class.getDeclaredMethod("getOriginalMetadata");
getMetadata.setAccessible(true);
Object o = getMetadata.invoke(d);
if (o instanceof ConfigurationBoundExternalDependencyMetadata) {
ConfigurationBoundExternalDependencyMetadata m = (ConfigurationBoundExternalDependencyMetadata)o;
ExternalDependencyDescriptor dd = m.getDependencyDescriptor();
if (dd instanceof MavenDependencyDescriptor) {
MavenDependencyDescriptor mdd = (MavenDependencyDescriptor)dd;
IvyArtifactName da = mdd.getDependencyArtifact();
if (da != null) {
classifier = da.getClassifier();
// This only works starting with Gradle 6.3:
List<org.gradle.api.artifacts.DependencyArtifact> as = d.getArtifactSelectors();
if (as != null && as.size() > 0) {
classifier = as.get(0).getClassifier();
}
} catch (NoSuchMethodError ex) {
// So try to get the classifier some other way...
try {
if (d instanceof AbstractDependencyMetadataAdapter) {
Method getMetadata = AbstractDependencyMetadataAdapter.class.getDeclaredMethod("getOriginalMetadata");
getMetadata.setAccessible(true);
Object o = getMetadata.invoke(d);
if (o instanceof ConfigurationBoundExternalDependencyMetadata) {
ConfigurationBoundExternalDependencyMetadata m = (ConfigurationBoundExternalDependencyMetadata)o;
ExternalDependencyDescriptor dd = m.getDependencyDescriptor();
if (dd instanceof MavenDependencyDescriptor) {
MavenDependencyDescriptor mdd = (MavenDependencyDescriptor)dd;
IvyArtifactName da = mdd.getDependencyArtifact();
if (da != null) {
classifier = da.getClassifier();
}
}
}
}
} catch (ReflectiveOperationException e) {
logger.warn("Could not get the classifier of " + d + ": " + e);
}
} catch (ReflectiveOperationException e) {
logger.warn("Could not get the classifier of " + d + ": " + e);
}
final String c = classifier;
if (classifier != null && platform.stream()
Expand Down

0 comments on commit 9098dcd

Please sign in to comment.