Scala新手Windows配置sbt 1.x连接Nexus仓库失败求助
Hey there! I’ve been in your exact situation before—getting sbt to play nice with a corporate Nexus repo instead of the default Maven Central can feel a bit tricky at first, but let’s walk through this step by step to get you up and running.
1. Set Up Global Repository Configuration (Applies to All Projects)
On Windows, sbt checks for a global repo config file at C:\Users\<YourUsername>\.sbt\repositories. If this file doesn’t exist, create it with a text editor like Notepad or VS Code.
Paste in the following content, replacing the placeholder URLs with your company’s actual Nexus repository addresses:
[repositories] local my-nexus-releases: https://your-company-nexus-url/repository/maven-releases/ my-nexus-snapshots: https://your-company-nexus-url/repository/maven-snapshots/ # Optional: If your Nexus proxies Maven Central, replace the default central with this line # central: https://your-company-nexus-url/repository/maven-central/
localkeeps sbt’s cached local dependencies (always leave this in place)my-nexus-releasespoints to your team’s stable release repositorymy-nexus-snapshotsis for snapshot builds (remove this if your team doesn’t use snapshots)
2. Add Nexus Authentication (If Required)
If your company’s Nexus requires a username and password, set up credentials like this:
- Create a file named
.credentialsinC:\Users\<YourUsername>\.sbt\ - Fill it with this template, replacing the placeholders:
realm=Sonatype Nexus Repository Manager host=your-company-nexus-url user=your-nexus-username password=your-nexus-password
- To make sbt load these credentials globally, create or edit
C:\Users\<YourUsername>\.sbt\1.0\global.sbtand add:
credentials += Credentials(Path.userHome / ".sbt" / ".credentials")
3. Project-Specific Configuration (Optional)
If you only want one project to use Nexus (instead of all your projects), skip the global setup and add this to your project’s build.sbt file:
// Add Nexus resolvers resolvers ++= Seq( "My Nexus Releases" at "https://your-company-nexus-url/repository/maven-releases/", "My Nexus Snapshots" at "https://your-company-nexus-url/repository/maven-snapshots/" ) // Load credentials from the .credentials file we created earlier credentials += Credentials(Path.userHome / ".sbt" / ".credentials")
4. Test the Setup
Open a command prompt in your project directory and run:
sbt update
Check the output—you should see sbt pulling dependencies from your Nexus repo instead of the default Maven Central. If you hit errors, double-check your URLs, credentials, and make sure your Windows firewall isn’t blocking access to the Nexus server.
内容的提问来源于stack exchange,提问作者Vinit

