Configure maven to access nexus

There are three configuration methods for maven to access nexus, namely:

Project pom.xml, the highest priority;

User's settings.xml, in the priority, if the repository tag is not configured in pom.xml, use this configuration;

Maven's settings.xml has the lowest priority. This configuration is only used when neither the project pom.xml nor the user's settings.xml has a repository configured;

 

Project pom.xml configuration, add the following in pom.xml:

    <repositories>
        <repository>
            <id>public</id>
            <name>public</name>
            <url>http://localhost:8081/nexus/content/groups/public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>public</id>
            <name>public</name>
            <url>http://localhost:8081/nexus/content/groups/public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>

 

The above is configured to access the Public Repositories warehouse group of Nexus, the id and name are irrelevant, the important thing is that the url must be adapted.

Publish to Nexus, add the following to pom.xml:

    <distributionManagement>
        <repository>
            <id>releases</id>
            <url>http://localhost:8081/nexus/content/repositories/releases</url>
        </repository>
        <snapshotRepository>
            <id>snapshots</id>
            <url>http://localhost:8081/nexus/content/repositories/snapshots</url>
        </snapshotRepository>
    </distributionManagement>

Plugin configuration with source distribution, add the following to pom.xml:

    <build>
        <plugins>
            <!-- 发布源码,需要这个插件 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

 

Publishing requires nexus login

in user's settings.xml

        <!--配置nexus仓库认证信息 -->
        <server>
            <id>releases</id>
            <username>admin</username>
            <password>admin123</password>
        </server>
        <server>
            <id>snapshots</id>
            <username>admin</username>
            <password>admin123</password>
        </server>

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324990092&siteId=291194637