@@ -223,7 +223,7 @@ public ValueAndType(Class type) {
223
223
224
224
NbProjectInfoBuilder (Project project ) {
225
225
this .project = project ;
226
- this .adapter = sinceGradleOrDefault ("7.6" , () -> new GradleInternalAdapter . Gradle76 (project ), () -> new GradleInternalAdapter (project ));
226
+ this .adapter = sinceGradleOrDefault ("7.6" , () -> new GradleInternalAdapter (project ), () -> new GradleInternalAdapter . GradlePre76 (project ));
227
227
}
228
228
229
229
private NbProjectInfoModel model = new NbProjectInfoModel ();
@@ -367,11 +367,19 @@ private String dependenciesAsString(Task t, TaskDependency td) {
367
367
}
368
368
369
369
private void detectConfigurationArtifacts (NbProjectInfoModel model ) {
370
+ // JDK-8301046: Don't use Configuration::getName as a method reference. The bug, when
371
+ // compiling `Configuration::getName` against Gradle >= 8.4, causes javac to pick the
372
+ // wrong receiver target (invokeinterface on Named::getName) in the lambda bootstrap
373
+ // method params rather than the (correct per JLS) invokevirtual on the callsite's
374
+ // erasure type (Configuration). This will break at runtime when calling Gradle <8.4,
375
+ // as in earlier versions the Configuration class does not implement Named, and throws
376
+ // a BootstrapMethodError wrapping a LambdaConversionException. The lambda form:
377
+ // `c -> c.getName()` bootstraps correctly but costs an extra method def/indirection.
370
378
List <Configuration > configs = project .getConfigurations ()
371
379
.stream ()
372
380
.filter (Configuration ::isCanBeConsumed )
373
381
.filter (c -> !c .isCanBeResolved ())
374
- .sorted (Comparator .comparing (Configuration :: getName ))
382
+ .sorted (Comparator .comparing (c -> c . getName ())) // JDK-8301046
375
383
.collect (Collectors .toList ());
376
384
Map <String , Object > data = new HashMap <>();
377
385
for (Configuration c : configs ) {
@@ -1362,18 +1370,24 @@ private void detectArtifacts(NbProjectInfoModel model) {
1362
1370
}
1363
1371
}
1364
1372
Map <String , Object > archives = new HashMap <>();
1365
- beforeGradle ("5.2" , () -> {
1366
- // The jar.getCassifier() and jar.getArchievePath() are deprecated since 5.2
1367
- // These methods got removed in 8.0
1368
- project .getTasks ().withType (Jar .class ).forEach (jar -> {
1369
- archives .put (jar .getClassifier (), jar .getArchivePath ());
1370
- });
1371
- });
1372
- sinceGradle ("5.2" , () -> {
1373
- project .getTasks ().withType (Jar .class ).forEach (jar -> {
1374
- archives .put (jar .getArchiveClassifier ().get (), jar .getDestinationDirectory ().file (jar .getArchiveFileName ().get ()).get ().getAsFile ());
1375
- });
1376
- });
1373
+ Consumer <Jar > jarToArchivesClassifierAndPath =
1374
+ sinceGradleOrDefault (
1375
+ "5.2" ,
1376
+ () -> jar -> archives .put (jar .getArchiveClassifier ().get (), jar .getDestinationDirectory ().file (jar .getArchiveFileName ().get ()).get ().getAsFile ()),
1377
+ () -> {
1378
+ // The jar.getCassifier() and jar.getArchievePath() are deprecated since 5.2
1379
+ // These methods got removed in 8.0
1380
+ Method getClassifier = Jar .class .getMethod ("getClassifier" );
1381
+ Method getArchivePath = Jar .class .getMethod ("getArchivePath" );
1382
+ return jar -> {
1383
+ try {
1384
+ archives .put ((String ) getClassifier .invoke (jar ), (File ) getArchivePath .invoke (jar ));
1385
+ } catch (ReflectiveOperationException e ) {
1386
+ sneakyThrow (e );
1387
+ }
1388
+ };
1389
+ });
1390
+ project .getTasks ().withType (Jar .class ).forEach (jarToArchivesClassifierAndPath );
1377
1391
model .getInfo ().put ("archives" , archives );
1378
1392
}
1379
1393
@@ -1567,17 +1581,7 @@ private void detectDependencies(NbProjectInfoModel model) {
1567
1581
Function <ProjectDependency , Project > projDependencyToProject =
1568
1582
sinceGradleOrDefault (
1569
1583
"9.0" ,
1570
- () -> {
1571
- Method getPath = ProjectDependency .class .getMethod ("getPath" );
1572
- return dep -> {
1573
- try {
1574
- String path = (String ) getPath .invoke (dep );
1575
- return project .findProject (path );
1576
- } catch (ReflectiveOperationException e ) {
1577
- throw new UnsupportedOperationException (e );
1578
- }
1579
- };
1580
- },
1584
+ () -> dep -> project .findProject (dep .getPath ()), // getPath() added in Gradle 8.11
1581
1585
() -> ProjectDependency ::getDependencyProject ); // removed in Gradle 9
1582
1586
1583
1587
visibleConfigurations .forEach (it -> {
@@ -1884,22 +1888,25 @@ interface ExceptionCallable<T, E extends Throwable> {
1884
1888
private static <T extends Throwable > void sneakyThrow (Throwable exception ) throws T {
1885
1889
throw (T ) exception ;
1886
1890
}
1887
-
1888
- private <T , E extends Throwable > T sinceGradleOrDefault (String version , ExceptionCallable <T , E > c , Supplier <T > def ) {
1891
+
1892
+ private <T , E extends Throwable > T sinceGradleOrDefault (
1893
+ String version , ExceptionCallable <T , E > c , ExceptionCallable <T , E > def ) {
1894
+ ExceptionCallable <T , E > impl ;
1889
1895
if (GRADLE_VERSION .compareTo (GradleVersion .version (version )) >= 0 ) {
1890
- try {
1891
- return c .call ();
1892
- } catch (RuntimeException | Error e ) {
1893
- throw e ;
1894
- } catch (Throwable t ) {
1895
- sneakyThrow (t );
1896
- return null ;
1897
- }
1896
+ impl = c ;
1898
1897
} else if (def != null ) {
1899
- return def . get () ;
1898
+ impl = def ;
1900
1899
} else {
1901
1900
return null ;
1902
1901
}
1902
+ try {
1903
+ return impl .call ();
1904
+ } catch (RuntimeException | Error e ) {
1905
+ throw e ;
1906
+ } catch (Throwable t ) {
1907
+ sneakyThrow (t );
1908
+ return null ;
1909
+ }
1903
1910
}
1904
1911
1905
1912
private <T , E extends Throwable > T sinceGradle (String version , ExceptionCallable <T , E > c ) {
0 commit comments