Nexus3私服 基于命令行上传文件

上传方式

Maven 插件

-- maven-deploy-plugin:deploy-file
-- Maven 2 wagon-maven-plugin:upload-single

HTTP

-- REST API
-- 直接上传存储路径

特定格式客户端

Maven 2:Apache Maven 2、Apache Ant、Gradle
Docker:Docker CLI
PyPI:twine
NuGet:NuGet CLI
npm:npm CLI
Rubygems:gem CLI

一、基于Maven工具

Maven deploy plugin:http://maven.apache.org/plugins/maven-deploy-plugin/
wagon maven plugin:http://www.mojohaus.org/wagon-maven-plugin/

1.修改maven配置文件

提示:主要配置Nexus用户权限

vim /etc/maven/settings.xml


nexus
user
passwd

2.基于Maven deploy plugin:deploy-file

2.1.示例--不使用 pom 文件
mvn deploy:deploy-file \
-DgroupId=com.somecompany \
-DartifactId=project \
-Dversion=1.0.0 \
-DgeneratePom=true \
-Dpackaging=jar \
-DrepositoryId=nexus \
-Durl=http://localhost:8081/repository/maven-releases \
-Dfile=target/project-1.0.0.jar

解释:
-DrepositoryId:指定用户ID;
-DgroupId:指定组ID;
-DartifactId:指定Artifact ID;
-Dversion:指定版本;
-Dpackaging:指定包类型;
-Dfile:指定上传文件的路径;
-Durl:指定Repository URL 地址;

2.2.示例--使用 pom 文件
mvn deploy:deploy-file \
-DgeneratePom=false \
-DrepositoryId=nexus \
-Durl=http://localhost:8081/repository/maven-releases \
-DpomFile=pom.xml \
-Dfile=target/project-1.0.0.jar
2.3.上传实例
mvn deploy:deploy-file \
-DrepositoryId=nexus \
-DgroupId=somecompany \
-DartifactId=project \
-Dversion=1.0.0 \
-DgeneratePom=true \
-Dfile=info.txt \
-Durl=http://localhost:8081/repository/maven-releases/

3.基于Maven wagon-maven-plugin:upload-single

3.1.示例
mvn wagon:upload-single \
-Dwagon.serverId=nexus \
-Dwagon.url=http://localhost:8081/repository/raw-hosted/ \
-Dwagon.fromFile=fileToUpload.txt

注意: “wagon.serverId”属性值不是Nexus 存储库 ID,它是 settings.xml 文件中 部分的 元素值,它具有部署所需的凭据。

二、基于HTTP POST(API)

1.列出组件

GET /service/rest/v1/components
1.1.示例
curl -u admin:admin123 \
-X GET 'http://localhost:8081/service/rest/v1/components?repository=maven-central'

2.获取组件

GET /service/rest/v1/components/{id}/service/rest/v1/components/{id}
2.1.示例
curl -u admin:admin123 -X GET 'http://localhost:8081/service/rest/v1/components/bWF2ZW4tY2VudHJhbDo4ODQ5MWNkMWQxODVkZDEzNjYwYmUwMjE1MjI2NGUwZQ' -u admin:admin123 -X GET 'http://localhost:8081/service/rest/v1/components/bWF2ZW4tY2VudHJhbDo4ODQ5MWNkMWQxODVkZDEzNjYwYmUwMjE1MjI2NGUwZQ'

3.上传组件

Nexus 3.9.0 to 3.13.0 - POST /service/rest/beta/components
Nexus 3.13.0 and newer - POST /service/rest/v1/components

3.1.示例
curl -v -u admin:admin123 \
-X POST 'http://localhost:8081/service/rest/v1/components?repository=maven-releases' \
-F maven2.groupId=com.google.guava \
-F maven2.artifactId=guava \
-F maven2.version=24.0-jre \
-F [email protected] \
-F maven2.asset1.extension=jar \
-F [email protected] \
-F maven2.asset2.classifier=sources \
-F maven2.asset2.extension=jar

4.删除组件

DELETE /service/rest/v1/components/{id}
4.1.示例
curl -u admin:admin123 -X DELETE 'http://localhost:8081/service/rest/v1/components/bWF2ZW4tY2VudHJhbDo4ODQ5MWNkMWQxODVkZDEzNjYwYmUwMjE1MjI2NGUwZQ'

5.Maven

5.1.示例--不使用 pom.xml 文件
curl -v -u admin:admin123 \
-F "maven2.generate-pom=true" \
-F "maven2.groupId=com.example" \
-F "maven2.artifactId=commercial-product" \
-F "maven2.packaging=jar" \
-F "version=1.0.0" \
-F "maven2.asset1=@/absolute/path/to/the/local/file/product.jar;type=application/java-archive" \
-F "maven2.asset1.extension=jar" "http://localhost:8081/service/rest/v1/components?repository=maven-third-party"
5.2.示例--使用 pom.xml 文件
curl -v -u admin:admin123 \
-F "maven2.generate-pom=false" \
-F "maven2.asset1=@/olute/path/to/the/local/file/pom.xml" \
-F "maven2.asset1.extension=pom" \
-F "maven2.asset2=@/olute/path/to/the/local/file/product-1.0.0.jar;type=application/java-archive" \
-F "maven2.asset2.extension=jar" "http://localhost:8081/service/rest/v1/components?repository=maven-releases"

三、基于HTTP PUT(存储路径)

1.示例

curl -v -u admin:admin123 --upload-file pom.xml \ 
http://localhost:8081/repository/maven-releases/org/foo/1.0/foo-1.0.pom
解释:

-u:指定用户和密码;
--upload-file:指定上传文件;
http://localhost:8081:表示Nexus 3 UI;
maven-releases:表示存储库名称;
org:表示Group ID;
foo:表示Artifact ID;
1.0:表示Version;
foo-1.0.pom:表示文件名称;

2.上传

curl -v -u admin:admin123 --upload-file t.txt \
http://localhost:8081/repository/maven-releases/somecompany/project/1.0.0/project-1.0.0.txt

3.下载

curl -v -u  admin:admin123 http://localhost:8081/repository/maven-releases/somecompany/project/1.0.0/project-1.0.0.txt -o project-1.0.0.txt

四、基于API 上传Raw资源

必要参数

raw.directory
raw.assetN
raw.assetN.filename

1.上传

curl -v -u admin:admin123 \
-X POST 'http://localhost:8081/service/rest/v1/components?repository=raw' \
-F raw.directory=/ \
-F [email protected] \
-F raw.asset1.filename=test.tar.gz 

2.下载

 curl -O  http://localhost:8081/repository/raw/test.tar.gz

你可能感兴趣的:(Nexus3私服 基于命令行上传文件)