一个Springboot项目的build.gradle和Dockerfile

记录一个Springboot项目的build.gradle配置和Docker配置, show demo胜于解释步骤。

Build.gradle

-----------------------------------------------------------------------------------------------------
buildscript{

  repositories{

      jcenter()

//mavenCentral()

      maven{url"https://maven.aliyun.com/repository/central"}

      maven{ url"https://plugins.gradle.org/m2/" }

}

  dependencies{

      classpath'com.google.protobuf:protobuf-gradle-plugin:0.8.12'

      classpath'se.transmode.gradle:gradle-docker:1.2'

  }

}

plugins{

  id'org.springframework.boot' version'2.2.7.RELEASE'

  id'io.spring.dependency-management' version'1.0.9.RELEASE'

  id'java'

}

applyplugin:'java'

applyplugin:'com.google.protobuf'

applyplugin:'docker'

group ='com.lifeccp.doctorwallet'

version ='1.0.0'

sourceCompatibility ='1.8'

sourceSets{

  main{

      proto{

        // In addition to the default 'src/main/proto'

        srcDir'src/main/portobuffer'

        include'**/*.protodevel'

      }

      test{

        proto{

            // In addition to the default 'src/test/proto'

            srcDir'src/test/protos'

        }

}

}

}

protobuf{

  generatedFilesBaseDir ="$projectDir/src"

}

configurations{

  developmentOnly

runtimeClasspath{

      extendsFrom developmentOnly

}

}

repositories{

  //mavenCentral()

  maven{url"https://maven.aliyun.com/repository/central"}

  maven{ url"http://scm.lifeccp.com:10060/nexus/content/groups/public/" }

}

dependencies{

  testCompile('org.springframework.boot:spring-boot-starter-test')

compile('org.springframework.boot:spring-boot-starter-web',

'org.springframework.boot:spring-boot-starter-undertow',

'org.springframework.boot:spring-boot-devtools',

'org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.1',

'com.spring4all:swagger-spring-boot-starter:1.7.0.RELEASE',

'de.codecentric:spring-boot-admin-starter-client:2.0.5',

'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.1.2'

  )

compile(

'mysql:mysql-connector-java:5.1.41',

'org.apache.httpcomponents:httpclient:4.5.3',

'com.alibaba:druid:1.1.5',

'org.hyperledger.sawtooth:sawtooth-sdk-signing:v0.1.2',

'org.hyperledger.sawtooth:sawtooth-sdk-transaction-processor:v0.1.2',

'com.google.protobuf:protobuf-java:3.10.0',

'org.web3j:core:4.5.12'

  )

//compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-client')

}

protobuf.protoc{

  artifact ='com.google.protobuf:protoc:3.0.0'

}

dependencyManagement{

  imports{

      mavenBom"org.springframework.cloud:spring-cloud-dependencies:Finchley.RELEASE"

  }

}

test{

  useJUnitPlatform()

}

task buildDocker(type: Docker,dependsOn: build){

  applicationName ='doctorwallet'

  tagVersion='1.0.0'

  dockerfile = file('Dockerfile')

doFirst{

      copy{

        from jar

into stageDir

}

}

}

----------------------------------------------------------------------------

dockerfile

-----------------------------------------------------------------------------------

FROM daocloud.io/library/java:8-alpine

MAINTAINER Charles Lin"[email protected]"

EXPOSE 8080

VOLUME /temp

ADD doctorwallet-1.0.0.jar doctorwallet.jar

RUN sh-c'touch doctorwallet.jar'

ENTRYPOINT ["java","-jar","doctorwallet.jar" ]

---------------------------------------------------------------------------------------------------------------------

使用gradle 的buildDocker task完成build

你可能感兴趣的:(一个Springboot项目的build.gradle和Dockerfile)