gradle 项目构建以及发布maven 私服&& docker 私服构建发布

1. 项目结构


 
2. 代码说明
a. Dockerfile docker 构建的

FROM openjdk:8-jre-alpine
WORKDIR /appdemo/
COPY  build/distributions/ratpackdemo.zip /appdemo
RUN  unzip /appdemo/ratpackdemo.zip
EXPOSE 5050
ENTRYPOINT [ "./ratpackdemo/bin/ratpackdemo"]

b. build.gradle

buildscript {
  repositories {
    jcenter()
  }
  dependencies {
    classpath "io.ratpack:ratpack-gradle:1.5.1"
    classpath('se.transmode.gradle:gradle-docker:1.2')
  }
}
project.group="com.dalong"
version="1.0-SNAPSHOT"
apply plugin: "io.ratpack.ratpack-java"
apply plugin: "idea"
apply plugin: "docker"
apply plugin: "maven"
repositories {
  jcenter()
}
uploadArchives {
    repositories.mavenDeployer {
        repository(url: "http://nexushost:8081/nexus/content/repositories/snapshots") {
            authentication(userName: "username", password: "userpassword")
            project.group="com.dalong"
            version="1.0-SNAPSHOT"
            pom.groupId = "com.dalong"
            pom.artifactId = "mydemo-ratpack"
        }
    }
}
distZip {
    archiveName = 'ratpackdemo-1-1.zip'
}
dependencies {
  runtime "org.slf4j:slf4j-simple:1.7.25"
}
task buildDocker(type:Docker,dependsOn: build){
  push = false
	applicationName = distZip.archiveName
	project.group="dockerimagehost/mydemo"
	dockerfile = file("${projectDir}/src/main/docker/Dockerfile")
  doFirst {
		copy {
			from distZip
			into stageDir
		}
 }
}
mainClassName = "dalong.Application"

c. 项目代码
省略比较简单,可以参考下面的参考地址
https://github.com/rongfengliang/ratpackdemo
3. 构建
./gradlew buildDocker  uploadArchives
4. 可能碰到的问题
注意以下代码
uploadArchives {
    repositories.mavenDeployer {
        repository(url: "http://nexushost:8081/nexus/content/repositories/snapshots") {
            authentication(userName: "username", password: "userpassword")
            project.group="com.dalong"
            version="1.0-SNAPSHOT"
            pom.groupId = "com.dalong"
            pom.artifactId = "mydemo-ratpack"
        }
    }
}
中version 对于对应maven仓库应该包含对应的 release 后者  SNAPSHOT 不然会存在发布提示400 的错误
5. 参考资料
https://github.com/rongfengliang/ratpackdemo
https://github.com/Transmode/gradle-docker

posted on 2018-02-01 10:11  荣锋亮  阅读(355)  评论(0编辑  收藏  举报

导航