-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sbt picks up Scala case classes generated by Java annotation processor
- Loading branch information
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import sbt.* | ||
import sbt.Keys.* | ||
|
||
import java.nio.file.attribute.BasicFileAttributes | ||
import java.nio.file.{FileVisitResult, Files, Path, SimpleFileVisitor} | ||
import scala.collection.mutable.ListBuffer | ||
|
||
object Utils { | ||
|
||
/** Recursively lists all `*.scala` files in the `target/src_managed` directory. | ||
* Should be put as a dependency of `Compile / managedSources` task to ensure | ||
* that sbt picks up any scala sources generated by the Java annotation processor. | ||
* @return | ||
*/ | ||
def listAllGeneratedScalaFiles(): Def.Initialize[Task[Seq[File]]] = Def.task { | ||
val srcManagedDir = (Compile / sourceManaged).value | ||
val scalaFiles = ListBuffer[Path]() | ||
|
||
Files.walkFileTree( | ||
srcManagedDir.toPath, | ||
new SimpleFileVisitor[Path]() { | ||
override def visitFile( | ||
file: Path, | ||
attrs: BasicFileAttributes | ||
): FileVisitResult = { | ||
if (file.toString.endsWith(".scala")) { | ||
scalaFiles += file | ||
} | ||
FileVisitResult.CONTINUE | ||
} | ||
} | ||
) | ||
|
||
scalaFiles.map(_.toFile) | ||
} | ||
} |