12
votes

We managed our maven repository using Sonatype Nexus, and in the ~.m2\setting.xml, set

<mirrorOf>*</mirrorOf>

to our Nexus repository.

In IntelliJ IDEA "Settings-->Maven-->Repositories-->Indexed Maven repositories", there are one local repository and one remote central repository "http://repo1.maven.org/maven2". However, there seems to be no way to index Nexus repository.

Without the index, I can't use the "Maven Artifact Search" inside IntelliJ IDEA, instead I have to search it in Nexus website, and then copy the dependency to the pom.xml, which is not quite convenient.

Can anybody tell me how to add Nexus repository index in IntelliJ IDEA, so that I can search artifacts inside IDEA?

below is my settings.xml:

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" 
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

  <mirrors>
    <mirror>
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
      <name>My repository</name>
      <url>http://1.2.3.4:8081/nexus/content/groups/public</url>
    </mirror>
  </mirrors>

  <profiles>
    <profile>
      <id>nexus</id>
      <repositories>
        <repository>
          <id>central</id>
          <name>My repository</name>
          <url>http://repo1.maven.org/maven2</url>
          <layout>default</layout>
          <releases>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
            <checksumPolicy>warn</checksumPolicy>
          </releases>
          <snapshots>
            <enabled>true</enabled>
            <updatePolicy>never</updatePolicy>
            <checksumPolicy>fail</checksumPolicy>
          </snapshots>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <url>http://repo1.maven.org/maven2</url>
          <releases>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
            <checksumPolicy>warn</checksumPolicy>
          </releases>
          <snapshots>
            <enabled>true</enabled>
            <updatePolicy>never</updatePolicy>
            <checksumPolicy>fail</checksumPolicy>
          </snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>

  <activeProfiles>
    <activeProfile>nexus</activeProfile>
  </activeProfiles>
</settings>
1
Check if you are using your local Maven installation or the built-in from IntelliJ. Do so by checking under Maven in your settings. - Rafael Winterhalter
I used local Maven installation. - fengyun
Then this answers your question: stackoverflow.com/questions/10676796/… - Make sure you update your Maven indices. You can do so in your Maven panel on the right. - Rafael Winterhalter
I edited the question and added my settings.xml. With this setting, the "Indexed Maven Repositories" would be a local repository and remote "repo1.maven.org/maven2", not Nexus url. What's worse, it says "Error" if I try to update remote repository index. - fengyun

1 Answers

2
votes

AFA I know this isn't possible, using IntelliJ IDEA 13.1. The only Maven repositories that are supported are local or public ones, per the docs: https://www.jetbrains.com/idea/help/maven-repositories.html

@CrazyCoder, correct me if I'm wrong...

Related: Adding maven repo in IntelliJ