如何使用gradle将客户端和服务器构建合并到一个jar中

如何使用gradle将客户端和服务器构建合并到一个jar中

本文介绍了如何使用gradle将客户端和服务器构建合并到一个jar中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个结构如下的项目:

I have a project with the following structure:

web-client/     # Angular Client
  build/
  build.gradle

server/         # Spring Boot Application
  build/
  build.gradle

build.gradle    # The "parent" project. Works on web-client and server

应该将已编译的Web应用程序复制到 server/build/classes/static 中,以便将其复制到/BOOT-INF最终的 jar 的/classes/,Spring Boot服务器将在其中提供该服务.

The parent is supposed to copy the compiled web-application into server/build/classes/static such that it will be copied to /BOOT-INF/classes/ of the final jar where it will be served by the Spring Boot server.

到目前为止,除最后一部分外,其他所有东西都在工作.这些文件也不会被复制到最终的 jar 中,我认为这是因为在执行复制任务时已经生成了这些文件.

Everything is working so far except the last part. Those files are nor copied into the final jar and I think it's because it got already build at the time where the copying task is executed.

这是我当前正在使用的脚本:

This is the script which I am currently using:


task buildWebApp {
    outputs.dir('mobile-client/build')
    dependsOn ':mobile-client:buildWebApp'
}

task copyWebApp {
    doFirst {
        copy {
            from 'mobile-client/build'
            into 'server/build/classes/static'
        }
    }
    dependsOn tasks.buildWebApp
}

# assemble.dependsOn copyWebApp
build.dependsOn copyWebApp

如何确保来自 mobile-client/build 的那些文件最终位于 server 的最终jar中?

How can I make sure that those files from mobile-client/build end up in the final jar of server?

推荐答案

不能保证其当前功能,但这是几年前在我的一个项目中使用的.我确实使用了单独的gradle子模块来构建Frontend,然后使用了用于Backend的单独模块,其中将Frontend包括为JAR:

Cannot guarantee its current functionality, but this I used in one of my projects a few years ago. I did use separate gradle submodule for building Frontend and then separate module for Backend where I included Frontend as a JAR:

root gradle project -> frontend
                    -> backend

Frontend build.gradle(使用/static/**构建前端JAR)

apply plugin: "com.moowork.node"
apply plugin: 'java'

node {
  version = '8.9.3'
  download = true
}

def webResources = "$buildDir/web-resources/main"

sourceSets {
  main {
    output.dir(webResources, builtBy: 'buildWeb')
  }
}

task webInstall(type: NpmTask) {
  args = ['install']
}

task buildWeb(type: NpmTask) {
  dependsOn webInstall
  args = ['run', 'build']
}

build.dependsOn buildWeb

后端build.gradle

apply plugin: 'spring-boot-gradle-plugin'
apply plugin: 'idea'

dependencies {
  compile project(':frontend')
}

这篇关于如何使用gradle将客户端和服务器构建合并到一个jar中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 17:09