32
32
public class DependencyResolver {
33
33
34
34
private static final String COMMAND_OUTPUT_LINE_PREFIX_CLASSPATH = "CLASSPATH:" ;
35
- private static final String CLASSPATH_CACHE_FILENAME = "JavaKitDependencyResolver.classpath. swift-java" ;
35
+ private static final String CLASSPATH_CACHE_FILENAME = "JavaKitDependencyResolver.swift-java.classpath " ;
36
36
37
37
public static String GRADLE_API_DEPENDENCY = "dev.gradleplugins:gradle-api:8.10.1" ;
38
38
public static String [] BASE_DEPENDENCIES = {
@@ -46,42 +46,42 @@ public class DependencyResolver {
46
46
@ UsedFromSwift
47
47
@ SuppressWarnings ("unused" )
48
48
public static String resolveDependenciesToClasspath (String projectBaseDirectoryString , String [] dependencies ) throws IOException {
49
- try {
50
- simpleLog ("Fetch dependencies: " + Arrays .toString (dependencies ));
51
- simpleLog ("projectBaseDirectoryString = " + projectBaseDirectoryString );
52
- var projectBasePath = new File (projectBaseDirectoryString ).toPath ();
53
-
54
- File projectDir = Files .createTempDirectory ("java-swift-dependencies" ).toFile ();
55
- projectDir .mkdirs ();
56
-
57
- if (hasDependencyResolverDependenciesLoaded ()) {
58
- // === Resolve dependencies using Gradle API in-process
59
- simpleLog ("Gradle API runtime dependency is available, resolve dependencies..." );
60
- return resolveDependenciesUsingAPI (projectDir , dependencies );
61
- }
49
+ try {
50
+ simpleLog ("Fetch dependencies: " + Arrays .toString (dependencies ));
51
+ simpleLog ("Classpath: " + System .getProperty ("java.class.path" ));
52
+ var projectBasePath = new File (projectBaseDirectoryString ).toPath ();
62
53
63
- // === Bootstrap the resolver dependencies and cache them
64
- simpleLog ("Gradle API not available on classpath, bootstrap %s dependencies: %s"
65
- .formatted (DependencyResolver .class .getSimpleName (), Arrays .toString (BASE_DEPENDENCIES )));
66
- String dependencyResolverDependenciesClasspath = bootstrapDependencyResolverClasspath ();
67
- writeDependencyResolverClasspath (projectBasePath , dependencyResolverDependenciesClasspath );
68
-
69
- // --- Resolve dependencies using sub-process process
70
- // TODO: it would be nice to just add the above classpath to the system classloader and here call the API
71
- // immediately, but that's challenging and not a stable API we can rely on (hacks exist to add paths
72
- // to system classloader but are not reliable).
73
- printBuildFiles (projectDir , dependencies );
74
- return resolveDependenciesWithSubprocess (projectDir );
75
- } catch (Exception e ) {
76
- e .printStackTrace ();
77
- throw e ;
78
- }
54
+ File projectDir = Files .createTempDirectory ("java-swift-dependencies" ).toFile ();
55
+ projectDir .mkdirs ();
56
+
57
+ if (hasDependencyResolverDependenciesLoaded ()) {
58
+ // === Resolve dependencies using Gradle API in-process
59
+ simpleLog ("Gradle API runtime dependency is available, resolve dependencies..." );
60
+ return resolveDependenciesUsingAPI (projectDir , dependencies );
61
+ }
62
+
63
+ // === Bootstrap the resolver dependencies and cache them
64
+ simpleLog ("Gradle API not available on classpath, bootstrap %s dependencies: %s"
65
+ .formatted (DependencyResolver .class .getSimpleName (), Arrays .toString (BASE_DEPENDENCIES )));
66
+ String dependencyResolverDependenciesClasspath = bootstrapDependencyResolverClasspath ();
67
+ writeDependencyResolverClasspath (projectBasePath , dependencyResolverDependenciesClasspath );
68
+
69
+ // --- Resolve dependencies using sub-process process
70
+ // TODO: it would be nice to just add the above classpath to the system classloader and here call the API
71
+ // immediately, but that's challenging and not a stable API we can rely on (hacks exist to add paths
72
+ // to system classloader but are not reliable).
73
+ printBuildFiles (projectDir , dependencies );
74
+ return resolveDependenciesWithSubprocess (projectDir );
75
+ } catch (Exception e ) {
76
+ e .printStackTrace ();
77
+ throw e ;
78
+ }
79
79
}
80
80
81
81
82
82
/**
83
83
* Use an external {@code gradle} invocation in order to download dependencies such that we can use `gradle-api`
84
- * next time we want to resolve dependencies. This uses an external process and is sligtly worse than using the API
84
+ * next time we want to resolve dependencies. This uses an external process and is slightly worse than using the API
85
85
* directly.
86
86
*
87
87
* @return classpath obtained for the dependencies
@@ -158,7 +158,8 @@ private static void writeDependencyResolverClasspath(Path projectBasePath, Strin
158
158
/**
159
159
* Detect if we have the necessary dependencies loaded.
160
160
*/
161
- private static boolean hasDependencyResolverDependenciesLoaded () {
161
+ @ UsedFromSwift
162
+ public static boolean hasDependencyResolverDependenciesLoaded () {
162
163
return hasDependencyResolverDependenciesLoaded (DependencyResolver .class .getClassLoader ());
163
164
}
164
165
0 commit comments