【maven】把github当做自己的小仓库

这里以我的项目( jp-base )为例

设置仓库路径

在项目根目录下新建文件夹:repository

设置 pom.xml

设置 jar 发布地址,这里的url表示刚刚新建的 repository 路径(注意前面有个 file:

<distributionManagement>
	<repository>
		<id>for-git</id>
		<url>file:${basedir}/repository</url>
	</repository>
</distributionManagement>

引入依赖

设置 本项目的仓库地址,即代码在 github 上的下载地址

<repositories>
		<id>jp-base</id>
		<name>jp-base</name>
		<!-- 下面两个地址都可以用 -->
		<!-- url : https://github.com/JPCui/jp-base/raw/master/repository -->
		<url>https://raw.githubusercontent.com/<user>/<project>/master/repository</url>
	</repository>
</repositories>

额外配置(源码、Javadoc 等)

如果想要打包源码,可在项目中加入 maven-source-plugin

<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-source-plugin</artifactId>
	<version>3.0.1</version>
	<configuration>
		<attach>true</attach>
	</configuration>
	<executions>
		<execution>
			<phase>compile</phase>
			<goals>
				<goal>jar</goal>
			</goals>
		</execution>
	</executions>
</plugin>
<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-javadoc-plugin</artifactId>
	<version>2.9</version>
	<configuration>
		<attach>true</attach>
		<!-- 跳过 javadoc -->
		<skip>true</skip>
	</configuration>
	<executions>
		<execution>
			<goals>
				<goal>jar</goal>
			</goals>
		</execution>
	</executions>
</plugin>

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注