You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何正确发布sbt插件到本地文件仓库并实现依赖解析?

Fixing Local File Repository Resolution for SBT Plugins

Got it, let's walk through how to get your custom local file repository working for both publishing your plugin and resolving it in another project. The core issue here is that your consuming project doesn't know to look in /Users/jast/repo/localtrix/ for the plugin—sbt only checks default repositories like Maven Central and .ivy2/local by default.

Step 1: Ensure Your Plugin is Published in Maven Style

First, let's confirm your plugin project is set up to publish in a Maven-compatible layout (this makes resolution simpler than Ivy-style for custom file repos). In your plugin's build.sbt, add or verify these settings:

// Define your plugin's core coordinates (match these exactly in the consuming project)
organization := "org.me"
name := "sbt-plugin"
version := "1.2.3"

// Point to your custom local file repository
publishTo := Some(Resolver.file("Local Maven Repository", file("/Users/jast/repo/localtrix/")))

// Force Maven-style publishing (avoids Ivy-specific directory structures that can cause resolution headaches)
publishMavenStyle := true

After updating, re-run sbt publish to push the plugin to your repo with the correct layout. You’ll see the familiar Maven-style directory structure: /org/me/sbt-plugin/1.2.3/ containing the JAR, POM, and other necessary files.

Step 2: Configure the Consuming Project to Use Your Local Repository

In the project where you want to use the plugin, you need to tell sbt to check your custom repo when resolving plugins. Edit the project/plugins.sbt file:

  1. Add the custom resolver first (before the plugin dependency—order can matter for resolution):

    // Add your local file repository as a resolver for plugin dependencies
    resolvers += Resolver.file("Local Maven Repository", file("/Users/jast/repo/localtrix/"))
    
  2. Add the plugin dependency (note: you don’t need to include the Scala/sbt version suffix—sbt handles that automatically based on your project’s environment):

    addSbtPlugin("org.me" % "sbt-plugin" % "1.2.3")
    

Key Checks to Avoid Common Pitfalls

  • Double-check that the organization, name, and version in your plugin's build.sbt match exactly what you’re using in addSbtPlugin. Typos here are the #1 cause of resolution failures.
  • If you previously published an Ivy-style version of the plugin to your custom repo, delete those old files before re-publishing with Maven style—conflicting layouts can confuse sbt.
  • To debug, run sbt debug in the consuming project and look for lines about repository resolution. This will show you exactly which repos sbt is checking and why it can’t find the plugin.

That's it! Run sbt in your consuming project now, and it should resolve your plugin from the custom local file repository without issues.

内容的提问来源于stack exchange,提问作者Justin Kaeser

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 10:05:55