如何在IntelliJ IDEA中默认导出SBT项目的Compile依赖?
Solution to Export Compile-Scoped Dependencies from SBT Project to Non-SBT Project
Absolutely! You can fix this frustrating reset issue by configuring your SBT project (Project A) to automatically mark Compile-scoped dependencies as exported for IntelliJ IDEA. This way, the setting persists even after project rebuilds or reimports. Here's what you need to do:
Step 1: Add SBT IDEA Plugin Configuration
Open Project A's build.sbt file and add the following configuration to override how IntelliJ IDEA generates the module settings:
// Enable the SBT IDEA plugin to customize module generation enablePlugins(sbt.plugins.IdeaPlugin) // Adjust module dependencies to export Compile-scoped ones by default ideaModule := { val originalModule = ideaModule.value originalModule.copy( dependencies = originalModule.dependencies.map { dep => // Mark dependencies in Compile scope as exported; adjust logic if needed for other scopes dep.copy(exported = dep.scope.exists(_.name == "Compile")) } ) }
How This Works:
- The
IdeaPluginlets us tweak the module metadata that SBT generates for IntelliJ IDEA. - We modify each dependency in the module: if the dependency is in the
Compilescope, we setexported = true. This tells IDEA to make those dependencies available to any project that depends on Project A (like Project B).
Step 2: Apply the Configuration
- If you're using IDEA's Auto-import for SBT projects, the changes will take effect automatically after saving
build.sbt. - If not, run the
sbt ideacommand in Project A's root directory, then reimport the project into IDEA.
Verification
After applying the configuration:
- Go to Project B's module settings in IDEA.
- Check the dependency on Project A—you'll see the Compile-scoped dependencies from Project A are now marked as exported by default.
- Rebuild the project; the export setting won't reset anymore.
This approach ensures that the export behavior is defined in your SBT configuration (source-controlled, consistent across environments) instead of relying on IDEA's manual GUI settings that get overwritten.
内容的提问来源于stack exchange,提问作者Gabriel
相关产品推荐
相关产品推荐

