乐闻世界logo
搜索文章和话题

How do I get sbt to use a local maven proxy repository ( Nexus )?

1个答案

1

First, confirm that you have the URL of your local Nexus repository. This is typically the HTTP service address of the Nexus server, for example http://localhost:8081/repository/maven-public/.

Step 2: Configure SBT's Repository Settings

In the root directory of your SBT project, locate or create a file named repositories. You should specify the Nexus repository as a repository for dependency resolution in this file.

Here is an example of how to configure this file:

conf
[repositories] local my-maven-proxy-releases: http://localhost:8081/repository/maven-releases/ my-maven-proxy-snapshots: http://localhost:8081/repository/maven-snapshots/

In this configuration:

  • local indicates that SBT will first attempt to resolve dependencies from the local .ivy2 directory.
  • my-maven-proxy-releases and my-maven-proxy-snapshots are the links to your Nexus repository, used for release and snapshot versions respectively.

Step 3: Configure SBT to Use the repositories File

In your build.sbt file or the project's build.properties file, add the following settings to specify that SBT uses the repositories file:

scala
externalResolvers := { val repos = (Path.userHome / ".sbt" / "repositories").getLines. filterNot(_.startsWith("#")). map(_.split(":").last.trim). toList repos.map(sbt.Resolver.url("my-resolver")(_)) }

This code reads the repository URLs defined in the repositories file and configures them as the project's resolvers.

Step 4: Test the Configuration

After completing the configuration, run an SBT command such as sbt update to verify the configuration. If everything is set up correctly, SBT will download dependencies from your configured Nexus repository.

By following these steps, you can successfully configure SBT to use a local Maven proxy repository like Nexus. This approach accelerates dependency downloads and minimizes reliance on external network resources.

2024年8月15日 18:32 回复

你的答案