Skip to content

Instantly share code, notes, and snippets.

@vigack
Last active September 27, 2018 05:47
Show Gist options
  • Save vigack/ef368b87b3371456ef23f3469ed845e3 to your computer and use it in GitHub Desktop.
Save vigack/ef368b87b3371456ef23f3469ed845e3 to your computer and use it in GitHub Desktop.
自动化合并前端代码草稿
buildscript {
ext {
springBootVersion = '1.5.6.RELEASE'
}
repositories {
jcenter()
}
dependencies {
classpath "org.projectlombok:lombok:1.16.18"
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath "mysql:mysql-connector-java:5.1.35"
classpath('se.transmode.gradle:gradle-docker:1.2')
}
}
plugins {
id 'net.ltgt.apt' version '0.15'
id "com.ewerk.gradle.plugins.querydsl" version "1.0.9"
id "com.moowork.node" version "1.2.0"
id "com.dorongold.task-tree" version "1.3"
}
group = 'vigack'
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'war'
apply plugin: 'idea'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
jcenter()
}
configurations {
providedRuntime
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-web')
compile group: 'org.springframework.boot', name: 'spring-boot-starter-cache'
compile('org.apache.shiro:shiro-spring:1.2.4')
compile 'com.squareup.okhttp3:okhttp:3.9.0'
runtime('mysql:mysql-connector-java')
compileOnly('org.projectlombok:lombok')
compile 'org.apache.commons:commons-dbcp2:2.1.1'
compile('org.springframework.boot:spring-boot-starter-tomcat')
compile "io.springfox:springfox-swagger2:2.7.0"
compile "io.springfox:springfox-swagger-ui:2.7.0"
compile "com.querydsl:querydsl-jpa:4.1.3"
compile "com.querydsl:querydsl-apt:4.1.3"
compile group: 'commons-fileupload', name: 'commons-fileupload', version: '1.3.3'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.6'
compile group: 'org.dom4j', name: 'dom4j', version: '2.1.0'
compile group: 'org.apache.poi', name: 'poi', version: '3.17'
compile group: 'org.apache.poi', name: 'poi-ooxml', version: '3.17'
compile group: 'com.fasterxml.uuid', name: 'java-uuid-generator', version: '3.1.4'
compile group: 'commons-net', name: 'commons-net', version: '3.6'
compile group: 'com.jcraft', name: 'jsch', version: '0.1.54'
compile group: 'net.sf.ehcache', name: 'ehcache', version: '2.10.4'
compile group: 'org.apache.shiro', name: 'shiro-ehcache', version: '1.4.0'
testCompile('org.springframework.boot:spring-boot-starter-test')
providedCompile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0'
compile 'org.mapstruct:mapstruct-jdk8:1.2.0.Final'
annotationProcessor 'org.projectlombok:lombok'
annotationProcessor 'org.mapstruct:mapstruct-processor:1.2.0.Final'
}
war {
archiveName = 'ops.war'
}
querydsl {
querydslSourcesDir = 'src/main/java'
jpa = true
}
configurations {
querydsl.extendsFrom compileClasspath
}
idea {
module {
sourceDirs += file('build/generated/source/apt/main')
}
}
//---------------------------- UI construct BEGIN ----------------------------
node {
nodeModulesDir = file("${project.projectDir}/ops-node")
}
task pullUI(group: 'UI', description: 'Pull git submodule') {
doLast {
exec {
commandLine 'git', 'submodule', 'update', '--init', '--recursive'
}
exec {
commandLine 'git', 'submodule', 'update', '--remote'
}
}
}
task buildUI(type: NpmTask, group: 'UI', description: 'Build UI through npm run build', dependsOn: npmInstall) {
args = ['run', 'build']
}
task combineUI(type: Copy, group: 'UI', description: 'Copy dist file to main/resources', dependsOn: buildUI) {
into("${project.projectDir}/src/main/resources/")
from("${project.projectDir}/ops-node/dist/static") {
into("static")
}
from("${project.projectDir}/ops-node/dist") {
exclude "static/"
into("public")
}
}
processResources.dependsOn combineUI
npmInstall.dependsOn pullUI
//---------------------------- UI construct END ----------------------------
@vigack
Copy link
Author

vigack commented May 22, 2018

除了用gradle合并,还有其他几种思路:

  1. 直接在jenkins上编写脚本,拉取前端项目构建结果
  2. 沿用原有方式,将编译好的前端脚本加入版本控制,然后每次提交的时候,执行脚本更新拉取

用gradle联合构建看起来最为自动化,但是也导致构建时间大大延长,感觉都不很完美。
果然前后端分离的项目,用CDN部署才是合理的。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment