@@ -165,6 +165,11 @@ struct SwiftJavaBuildToolPlugin: SwiftJavaPluginProtocol, BuildToolPlugin {
165165 log ( " No dependencies to fetch for target \( sourceModule. name) " )
166166 }
167167
168+ // Add all the core Java stdlib modules as --depends-on
169+ let javaStdlibModules = getExtractedJavaStdlibModules ( )
170+ log ( " Include Java standard library SwiftJava modules: \( javaStdlibModules) " )
171+ arguments += javaStdlibModules. flatMap { [ " --depends-on " , $0] }
172+
168173 if !outputSwiftFiles. isEmpty {
169174 arguments += [ configFile. path ( percentEncoded: false ) ]
170175
@@ -236,3 +241,29 @@ extension SwiftJavaBuildToolPlugin {
236241 outputDirectory ( context: context, generated: generated) . appending ( path: filename)
237242 }
238243}
244+
245+ func getExtractedJavaStdlibModules( ) -> [ String ] {
246+ let fileManager = FileManager . default
247+ let sourcesPath = URL ( fileURLWithPath: #filePath)
248+ . deletingLastPathComponent ( )
249+ . deletingLastPathComponent ( )
250+ . appendingPathComponent ( " Sources " )
251+ . appendingPathComponent ( " JavaStdlib " )
252+
253+ guard let stdlibDirContents = try ? fileManager. contentsOfDirectory (
254+ at: sourcesPath,
255+ includingPropertiesForKeys: [ . isDirectoryKey] ,
256+ options: [ . skipsHiddenFiles]
257+ ) else {
258+ return [ ]
259+ }
260+
261+ return stdlibDirContents. compactMap { url in
262+ guard let resourceValues = try ? url. resourceValues ( forKeys: [ . isDirectoryKey] ) ,
263+ let isDirectory = resourceValues. isDirectory,
264+ isDirectory else {
265+ return nil
266+ }
267+ return url. lastPathComponent
268+ } . sorted ( )
269+ }
0 commit comments