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

如何配置Nexus仓库仅管理自行安装的JAR包,禁止拉取Maven Central内容

How to Configure Nexus to Only Manage Your Custom JARs (Stop Pulling from Maven Central)

Hey there! The issue you’re seeing is almost certainly because your current Nexus setup includes a proxy repository linked to Maven Central, or a repository group that includes that proxy. Proxies are designed to automatically fetch and cache artifacts from remote repos like Central. To fix this, we’ll set up a repository that only stores your own uploaded JARs, and adjust your configuration to use that exclusively.

Here’s a step-by-step breakdown:

1. Create a Hosted Maven Repository (if you don’t have one already)

Hosted repositories are built for storing your own artifacts—no remote fetching happens here.

  • Log into your Nexus instance, navigate to Repository Manager > Repositories.
  • Click Create repository and select maven2 (hosted) from the list.
  • Fill in the details:
    • Name: Pick something descriptive, like my-custom-jars
    • Version policy: Choose "Release" for stable builds, or "Snapshot" for development artifacts (you can create separate repos for each if needed)
    • Layout policy: Stick with "Strict" to follow the standard Maven directory structure
    • Write policy: Set to "Allow redeploy" if you need to overwrite existing artifacts (optional, based on your workflow)
  • Hit Create repository to save.

2. Adjust Your Repository Group (if you’re using one)

If your projects point to a group like maven-public, that group probably includes the default maven-central proxy. Let’s clean that up:

  • Go to your repository group (e.g., maven-public)
  • In the Member repositories section, find the maven-central proxy and click the trash icon to remove it
  • Add your new hosted repo to the group by clicking Add and selecting it from the dropdown
  • Save the changes. Now the group will only serve artifacts from your custom repo.

3. Update Your Project’s Maven Configuration

You need to ensure your Maven builds only look to your Nexus hosted repo for artifacts. Here are two ways to do this:

Option A: Global settings.xml (applies to all projects)

Edit ~/.m2/settings.xml (create it if it doesn’t exist) to point to your repo:

<settings>
  <mirrors>
    <mirror>
      <id>nexus-custom</id>
      <mirrorOf>central</mirrorOf>
      <url>http://your-nexus-url/repository/my-custom-jars/</url>
    </mirror>
  </mirrors>
  <profiles>
    <profile>
      <id>nexus</id>
      <repositories>
        <repository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
  <activeProfiles>
    <activeProfile>nexus</activeProfile>
  </activeProfiles>
</settings>

Option B: Project-specific pom.xml

Add this snippet to your project’s pom.xml to override repository settings just for that project:

<repositories>
  <repository>
    <id>my-custom-jars</id>
    <url>http://your-nexus-url/repository/my-custom-jars/</url>
    <releases>
      <enabled>true</enabled>
    </releases>
    <snapshots>
      <enabled>true</enabled>
    </snapshots>
  </repository>
</repositories>

<pluginRepositories>
  <pluginRepository>
    <id>my-custom-jars</id>
    <url>http://your-nexus-url/repository/my-custom-jars/</url>
    <releases>
      <enabled>true</enabled>
    </releases>
    <snapshots>
      <enabled>true</enabled>
    </snapshots>
  </pluginRepository>
</pluginRepositories>

4. Verify the Setup

  • Try building a project that depends on an artifact you haven’t uploaded to Nexus. It should throw a "not found" error (instead of fetching from Central)—that’s exactly what we want!
  • Upload one of your custom JARs to the hosted repo (via Nexus UI, or using mvn deploy), then rebuild the project. It should resolve the artifact successfully from your Nexus instance.

Quick Extra Tips

  • If you have old cached artifacts from Central in Nexus, you can delete them from the proxy repo (if you keep it) but since we’re no longer using that proxy, it won’t impact your new setup.
  • Make sure your Nexus user has permissions to upload artifacts: Check Security > Roles to ensure they have nx-repository-view-maven2-*-add and nx-repository-view-maven2-*-edit permissions for your hosted repo.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 03:44:52