Skip to content

Favor NIO over IO to avoid FileSystemExceptions on Windows #2566

@alexarchambault

Description

@alexarchambault

On Windows, when Bloop compiled a project using a locally published JAR, it seems it still holds an exclusive access to the file. This is a problem when one wants to overwrite the locally published artifact from a build tool. One gets errors like

native.publishLocal java.nio.file.FileSystemException: C:\Users\Alex\.ivy2\local\io.github.alexarchambault.native-terminal\native-terminal\0.0.7-SNAPSHOT\jars\native-terminal.jar: The process cannot access the file because it is being used by another process
    java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:92)
    java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
    java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:108)
    java.base/sun.nio.fs.WindowsFileSystemProvider.implDelete(WindowsFileSystemProvider.java:273)
    java.base/sun.nio.fs.AbstractFileSystemProvider.delete(AbstractFileSystemProvider.java:104)
    java.base/java.nio.file.Files.delete(Files.java:1152)
    os.remove$all$.apply(FileOps.scala:341)
    os.copy$over$.apply(FileOps.scala:300)
    mill.scalalib.publish.LocalIvyPublisher.$anonfun$publishLocal$2(LocalIvyPublisher.scala:46)
    scala.collection.immutable.List.map(List.scala:247)
    scala.collection.immutable.List.map(List.scala:79)
    mill.scalalib.publish.LocalIvyPublisher.publishLocal(LocalIvyPublisher.scala:44)
    mill.scalalib.PublishModule.$anonfun$publishLocalTask$2(PublishModule.scala:231)

Restarting the Bloop server solves that problem, but isn't very handy.

Favoring Java NIO over Java IO seems to solve that problem, like done here or here.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions