Maven为项目配置仓库

Maven为项目配置仓库

参考

https://mp.weixin.qq.com/s?__biz=MzA5MTkxMDQ4MQ==&mid=2648933541&idx=1&sn=8617c73b82d8aa4517a6357261a882b4&scene=19#wechat_redirect

https://blog.csdn.net/tiguer/article/details/80578660

https://segmentfault.com/a/1190000017402970

方式一 pom中配置仓库

方式二 profile中配置

方式三 配置镜像

所有项目都有的中央仓库

maven安装目录下的:/lib/maven-model-builder-${version}.jar中,打开该文件,能找到超级POM:\org\apache\maven\model\pom-4.0.0.xml,其中定义了所有项目都有的仓库即中央仓库。

<repositories>
    <repository>
        <id>central</id>
        <name>Central Repository</name>
        <url>https://repo.maven.apache.org/maven2</url>
        <layout>default</layout>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>

<pluginRepositories>
    <pluginRepository>
        <id>central</id>
        <name>Central Repository</name>
        <url>https://repo.maven.apache.org/maven2</url>
        <layout>default</layout>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
        <releases>
            <updatePolicy>never</updatePolicy>
        </releases>
    </pluginRepository>
</pluginRepositories>
<?xml version="1.0" encoding="UTF-8"?>

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->

<!-- START SNIPPET: superpom -->
<project>
    <modelVersion>4.0.0</modelVersion>

    <repositories>
        <repository>
            <id>central</id>
            <name>Central Repository</name>
            <url>https://repo.maven.apache.org/maven2</url>
            <layout>default</layout>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>central</id>
            <name>Central Repository</name>
            <url>https://repo.maven.apache.org/maven2</url>
            <layout>default</layout>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <releases>
                <updatePolicy>never</updatePolicy>
            </releases>
        </pluginRepository>
    </pluginRepositories>

    <build>
        <directory>${project.basedir}/target</directory>
        <outputDirectory>${project.build.directory}/classes</outputDirectory>
        <finalName>${project.artifactId}-${project.version}</finalName>
        <testOutputDirectory>${project.build.directory}/test-classes</testOutputDirectory>
        <sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
        <scriptSourceDirectory>${project.basedir}/src/main/scripts</scriptSourceDirectory>
        <testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>
        <resources>
            <resource>
                <directory>${project.basedir}/src/main/resources</directory>
            </resource>
        </resources>
        <testResources>
            <testResource>
                <directory>${project.basedir}/src/test/resources</directory>
            </testResource>
        </testResources>
        <pluginManagement>
            <!-- NOTE: These plugins will be removed from future versions of the super POM -->
            <!-- They are kept for the moment as they are very unlikely to conflict with lifecycle mappings (MNG-4453) -->
            <plugins>
                <plugin>
                    <artifactId>maven-antrun-plugin</artifactId>
                    <version>1.3</version>
                </plugin>
                <plugin>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <version>2.2-beta-5</version>
                </plugin>
                <plugin>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <version>2.8</version>
                </plugin>
                <plugin>
                    <artifactId>maven-release-plugin</artifactId>
                    <version>2.5.3</version>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

    <reporting>
        <outputDirectory>${project.build.directory}/site</outputDirectory>
    </reporting>

    <profiles>
        <!-- NOTE: The release profile will be removed from future versions of the super POM -->
        <profile>
            <id>release-profile</id>

            <activation>
                <property>
                    <name>performRelease</name>
                    <value>true</value>
                </property>
            </activation>

            <build>
                <plugins>
                    <plugin>
                        <inherited>true</inherited>
                        <artifactId>maven-source-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>attach-sources</id>
                                <goals>
                                    <goal>jar-no-fork</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <inherited>true</inherited>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>attach-javadocs</id>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <inherited>true</inherited>
                        <artifactId>maven-deploy-plugin</artifactId>
                        <configuration>
                            <updateReleaseInfo>true</updateReleaseInfo>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

</project>
<!-- END SNIPPET: superpom -->

案例 pom配置私服仓库并下载jar

<dependencies>
    <!--引入公共服务-->
    <dependency>
        <groupId>com.ytkj</groupId>
        <artifactId>ytkj_common_server</artifactId>
        <version>1.0.6</version>
    </dependency>
</dependencies>
<repositories>
    <repository>
        <id>central</id>
        <name>Central Repository</name>
        <url>https://repo.maven.apache.org/maven2</url>
        <layout>default</layout>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
    <repository>
        <id>ytkj</id>
        <name>ytkj的仓库</name>
        <!--<url>http://192.168.1.124:8081/nexus/content/groups/public/</url>-->
        <!--<url>http://192.168.1.124:8081/repository/ytkj_repo/</url>-->

        <!-- 可以完全下载下来私服上的jar -->
        <url>http://192.168.1.124:8081/#browse/browse:ytkj_repo</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>

profile中配置

<profiles>
    <profile>
      <id>boundlessgeo</id>
      <repositories>
        <repository>
          <id>boundlessgeo</id>
          <url>https://repo.boundlessgeo.com/main/</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
          </snapshots>
        </repository>
      </repositories>
    </profile>
    <profile>
      <id>aliyun</id>
      <repositories>
        <repository>
          <id>aliyun</id>
          <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
          </snapshots>
        </repository>
      </repositories>
    </profile>
    <profile>
      <id>maven-central</id>
      <repositories>
        <repository>
          <id>maven-central</id>
          <url>http://central.maven.org/maven2/</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
          </snapshots>
        </repository>
      </repositories>
    </profile>
<profiles>
<activeProfiles>
    <activeProfile>boundlessgeo</activeProfile>
    <activeProfile>aliyun</activeProfile>
    <activeProfile>maven-central</activeProfile>
</activeProfiles>

镜像方式

<mirrors>
    <!-- mirror
     | Specifies a repository mirror site to use instead of a given repository. The repository that
     | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
     | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
     -->
    <mirror>
        <id>nexus</id>
        <name>internal nexus repository</name>
        <!-- <url>http://192.168.1.100:8081/nexus/content/groups/public/</url>-->
        <url>http://repo.maven.apache.org/maven2</url>
        <mirrorOf>central</mirrorOf>
    </mirror>

    <mirror>
        <id>alimaven</id>
        <name>aliyun maven</name>
        <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
        <mirrorOf>central</mirrorOf>
    </mirror> 

    <mirror>
        <id>uk</id>
        <mirrorOf>central</mirrorOf>
        <name>Human Readable Name for this Mirror.</name>
        <url>http://uk.maven.org/maven2/</url>
    </mirror>

    <mirror>
        <id>CN</id>
        <name>OSChina Central</name>
        <url>http://maven.oschina.net/content/groups/public/</url>
        <mirrorOf>central</mirrorOf>
    </mirror>

</mirrors>

bug

E:\mozq\demo_project\http_01>mvn
[INFO] Scanning for projects...
Downloading from ytkj: http://192.168.1.124:8081/#browse/browse:ytkj_repo/org/springframework/boot/spring-boot-starter-parent/2.2.1.RELEASE/spring-boot-starter-parent-2.2.1.RELEASE.pom
[WARNING] Checksum validation failed, expected <!DOCTYPE but is a2007b11839d9c846015356d6f9fcdbcdc6cf34c from ytkj for http://192.168.1.124:8081/#browse/browse:ytkj_repo/org/springframework/boot/spring-boot-starter-parent/2.2.1.RELEASE/spring-boot-starter-parent-2.2.1.RELEASE.pom
[WARNING] Could not validate integrity of download from http://192.168.1.124:8081/#browse/browse:ytkj_repo/org/springframework/boot/spring-boot-starter-parent/2.2.1.RELEASE/spring-boot-starter-parent-2.2.1.RELEASE.pom: Checksum validation failed, expected <!DOCTYPE but is a2007b11839d9c846015356d6f9fcdbcdc6cf34c
[WARNING] Checksum validation failed, expected <!DOCTYPE but is a2007b11839d9c846015356d6f9fcdbcdc6cf34c from ytkj for http://192.168.1.124:8081/#browse/browse:ytkj_repo/org/springframework/boot/spring-boot-starter-parent/2.2.1.RELEASE/spring-boot-starter-parent-2.2.1.RELEASE.pom
Downloaded from ytkj: http://192.168.1.124:8081/#browse/browse:ytkj_repo/org/springframework/boot/spring-boot-starter-parent/2.2.1.RELEASE/spring-boot-starter-parent-2.2.1.RELEASE.pom (8.0 kB at 37 kB/s)
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-parseable POM C:\Users\1\.m2\repository\org\springframework\boot\spring-boot-starter-parent\2.2.1.RELEASE\spring-boot-starter-parent-2.2.1.RELEASE.pom: Expected root element 'project' but found 'html' (position: START_TAG seen ...<!DOCTYPE html>\n<html lang="en">... @3:17)  @ C:\Users\1\.m2\repository\org\springframework\boot\spring-boot-starter-parent\2.2.1.RELEASE\spring-boot-starter-parent-2.2.1.RELEASE.pom, line 3, column 17

原文地址:https://www.cnblogs.com/mozq/p/12030595.html

时间: 2024-11-05 23:36:50

Maven为项目配置仓库的相关文章

myeclipse maven web项目配置

启用maven:window-->preference-->MyEclipse-->Maven4MyEclipse, 勾选复选框(Enable Mave4MyEclipse features 一个简单的maven项目结构: mywebapp +---pom.xml +---src +---main +---resources +---webapp +---index.jsp +---WEB-INF +---web.xml 安装maven的配置 apache maven项目官网: http

maven多层项目配置

今天遇到一个maven项目有3个子项目的配置问题,一开始项目结构是混乱的,而且包引入不能正常解析. 主项目上右键,选择configure->configure and detect nested projects,整个项目的结构就归于正常了.

Maven Web项目配置Mybatis出现SqlSessionFactory错误的解决方案

一.错误现象 [html] view plain copy 严重: Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.mybatis.spring.mapper.MapperScannerConfigurer#0' defined in URL [file:/F:/Workspaces/.metadata

maven环境搭建+eclipse插件安装+基本项目配置

今天学了下maven环境搭建,及项目的部署,总结下.公司最近在用maven+jekins自动发布,于是就有了想法学学,正好用到一直在学习的自动化测试中. 1.软件下载: A.Maven3.0.5 下载地址: http://www.xdowns.com/soft/38/121/2013/Soft_105445.html 当然也可以到官网下载:http://maven.apache.org/   --一直打不开 B.eclipse下载,百度上很多 此处略 C.jdk安装此处略,配置好环境变量 2.m

maven的安装以及配置仓库

maven概述:Maven是一个跨平台的项目管理工具,主要基于java平台的项目构建,依赖管理. maven解决的问题: 1)如果有好几个项目,这几个项目中,需要用到很多相同的jar包,能不能只是建立一个仓库来解决这个问题? 2)测试方法能不能全部运行? 3)怎么把一个模块的功能放入到仓库中 maven的安装: 1)maven是依赖于java平台,因此需要jdk的支持,jdk的安装,这里就不再陈述 2)从官网下载maven 3)配置环境变量(apche的东西 貌似都要配置环境变量) 计算机右键属

整理这几天搭建web项目更新的maven知识及项目配置

一.maven基本知识 1.groupid.artifactId.version 用eclipse ee创建web项目时需要输入groupid.artifactId.version,它们是什么呢?        groupId:组织标识,例如com.baobaotao.ide,在本地仓库下将是com/baobaotao/ide.        artifactId: 项目名称,例如shop,在本地仓库目录下将是com/baobaotao/ide/shop.        version:版本号,

Maven 安装与配置 与 Maven 私服仓库安装

Maven是一个项目管理和整合的工具,主要服务于基于Java平台的项目构建n为开发者提供了一套完整的构建生命周期框架. 一.Maven下载安装与配置 1.下载与安装 http://maven.apache.org/download.cgi 根据本地操作系统类型选择对应的安装包 比如,我在Windows下安装了 Maven3.2.1 2.配置环境变量 “我的电脑”或“计算机”à属性à高级选项->环境变量 新建系统变量MAVEN_HOME变量值为:Maven安装根目录 修改Path变量在最后加上:号

IDEA 配置maven + SpringBoot项目在新电脑上的配置运行

该教程记录了我在一台新的电脑上安装IDEA,配置JAVA+MAVEN+GIT+SpringBoot项目的过程,最终完成了项目的运行. 一.若想利用IDEA的git工具从GitHub或者码云上面获取项目,需要提前下载git软件,并完成初步的配置. 1. git的下载和配置  进入git官网,https://www.git-scm.com/downloads并下载. 确定自己要下载的版本(我下载的是64bit版本的windows安装程序),点击下载即可. 下载完之后,双击应用程序,一路next即可完

maven安装和配置及创建maven项目

(1)下载maven,下载成功后,解压到本地磁盘 里面包含这几项 (2)配置maven环境变量MAVEN_HOME.path (3)最后检验配置是否成功:用win键+R,来打开命令行提示符窗口,即Dos界面,输入mvn -v(mvn --version) 若出现以下情况说明配置成功 2.maven配置本地仓库存放位置 (1)找到apache-maven-3.0.4下的conf 下的 settings.xml 配置文件,我的是在 D:\Program Files(x86)\apache-maven