为了账号安全,请及时绑定邮箱和手机立即绑定

干货:Docker 1分钟搭建Maven仓库Nexus3

标签:
Java Linux Docker

这里使用最新版本的nexus3.11作为演示,nexus作为maven构建的仓库。

使用演示

依赖docker

非挂载方式运行

docker run -p 8081:8081 -dti dounine/nexus /nexus/bin/nexus run

将仓库文件保存到本地方式运行

docker run -p 8081:8081 -v /xxxx/nexus/storage:/sonatype-work -dti dounine/nexus /nexus/bin/nexus run

访问http://localhost:8081
默认用户与密码:admin admin123
nexus

Java gradle简单配置使用

build.gradle

apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'maven-publish'
group 'com.dounine.nexus'
sourceCompatibility = 1.8
version = '0.0.1-SNAPSHOT'
ext {
    nexusUrl="http://localhost:8081"
    username="admin"
    password="admin123"
}
uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: "${nexusUrl}/repository/maven-releases/") {
                authentication(userName: "${username}", password: "${password}")
            }
            snapshotRepository(url: "${nexusUrl}/repository/maven-snapshots/") {
                authentication(userName: "${username}", password: "${password}")
            }
        }
    }
}

repositories {
    maven {
        if (project.version.endsWith('-SNAPSHOT')) {
            url = "${nexusUrl}/repository/maven-snapshots/"
        } else {
            url = "${nexusUrl}/repository/maven-releases/"
        }
        credentials {
            username "${username}"
            password "${password}"
        }
    }
    mavenLocal()
    mavenCentral()
}

打包代码上传到仓库

gradle uploadArchives

显示结果如下

gradle uploadArchives
Could not find metadata com.dounine.nexus:api:0.0.1-SNAPSHOT/maven-metadata.xml in remote (http://localhost:8081/repository/maven-snapshots/)
Could not find metadata com.dounine.nexus:api/maven-metadata.xml in remote (http://localhost:8081/repository/maven-snapshots/)

BUILD SUCCESSFUL in 0s
3 actionable tasks: 1 executed, 2 up-to-date
点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 1
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消