springboot集成java+groovy+lombok混合编程使用maven多模块打包实例

springboot多模块打包实例

由于在项目中引入了groovy编程,并且使用了lombok,在运行时没发现什么问题,但是最后打包部署时出现一系列问题。查了许久资料终于解决,特将解决方案写成文档记录一下

项目结构

upms-integrate      父模块
├─upms-base         公共模块
│
├─upms-web          管理后台-web
│
├─upms-generator    代码生成器

upms-admin模块依赖upms-base模块

maven打包各模块配置

  • upms-integrate父模块
<groupId>com.zzgroupId>
<artifactId>upms-integrateartifactId>
<version>0.0.1-SNAPSHOTversion>
<modules>
    <module>upms-basemodule>
    <module>upms-webmodule>
    <module>upms-generatormodule>
modules>

<packaging>pompackaging>
.
.
.
  • upms-base公共模块配置
<parent>
    <artifactId>upms-integrateartifactId>
    <groupId>com.zzgroupId>
    <version>0.0.1-SNAPSHOTversion>
parent>

<modelVersion>4.0.0modelVersion>
<artifactId>upms-baseartifactId>

<packaging>jarpackaging>
.
.
.
<resources>
    
    <resource>
        <directory>src/main/javadirectory>
        <includes>
            <include>**/*.propertiesinclude>
            <include>**/*.xmlinclude>
        includes>
        <filtering>falsefiltering>
    resource>
    
    <resource>
        <directory>src/main/resourcesdirectory>
        <includes>
            <include>**/*.propertiesinclude>
            <include>**/*.xmlinclude>
            <include>**/*.tldinclude>
            <include>**/*.capinclude>
            <include>**/*.txtinclude>
        includes>
        <excludes>
            <exclude>mybatis-generator/*.*exclude>
        excludes>
        <filtering>falsefiltering>
    resource>
resources>

  • upms-web模块
<parent>
    <artifactId>upms-integrateartifactId>
    <groupId>com.zzgroupId>
    <version>0.0.1-SNAPSHOTversion>
parent>
<modelVersion>4.0.0modelVersion>
<artifactId>upms-webartifactId>

<packaging>jarpackaging>
<name>upms-webname>
.
.
.
<build>
    <finalName>upmsfinalName>
    <resources>
        <resource>
            
            <directory>src/main/resourcesdirectory>
            <filtering>falsefiltering>
            <excludes>
                <exclude>static/**exclude>
            excludes>
            <includes>
                <include>**include>
            includes>
        resource>
    resources>

    <plugins>
        <plugin>
            
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-maven-pluginartifactId>
        plugin>
    plugins>
build>

各模块按以上配置后,即可使用mvn clean install/package 指令打包了。
也可以使用-pl upms-web指定打包模块,前提是要先把该模块依赖的所有子模块安装到本地或远程仓库

(重点)springboot在混合java+groovy编程并且使用lombok的情况下打包配置

java混合groovy打包需要使用groovy-eclipse-compiler插件,并且在引入了lombok的情况下又会有一些问题。
解决方法为:上述各模块配置不变,在父模块中增加以下配置

https://github.com/groovy/groovy-eclipse/wiki/Groovy-Eclipse-Maven-plugin

<properties>
    <project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8project.reporting.outputEncoding>
    <java.version>1.8java.version>
    <groovy.version>2.4.15groovy.version>
    <lombok.version>1.16.18lombok.version>
    <groovy.eclipse.compiler.version>2.9.2-01groovy.eclipse.compiler.version>
    <groovy.eclipse.batch.version>2.4.3-01groovy.eclipse.batch.version>
properties>

<dependencies>
    
    <dependency>
        <groupId>org.codehaus.groovygroupId>
        <artifactId>groovy-allartifactId>
        <classifier>indyclassifier>
        <version>${groovy.version}version>
    dependency>
    <dependency>
        <groupId>org.projectlombokgroupId>
        <artifactId>lombokartifactId>
        <version>${lombok.version}version>
        <scope>providedscope>
    dependency>
dependencies>    
<build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-pluginartifactId>
            <version>3.6.0version>
            <configuration>
                <source>1.8source>
                <target>1.8target>
                <encoding>UTF-8encoding>
                <compilerId>groovy-eclipse-compilercompilerId>
                <verbose>trueverbose>
                
                <compilerArguments>
                    
                    <javaAgentClass>lombok.launch.AgentjavaAgentClass>
                compilerArguments>
                <fork>truefork>
            configuration>
            <dependencies>
                <dependency>
                    <groupId>org.codehaus.groovygroupId>
                    <artifactId>groovy-eclipse-compilerartifactId>
                    <version>${groovy.eclipse.compiler.version}version>
                dependency>
                
                <dependency>
                    <groupId>org.codehaus.groovygroupId>
                    <artifactId>groovy-eclipse-batchartifactId>
                    <version>${groovy.eclipse.batch.version}version>
                dependency>
                <dependency>
                    <groupId>org.codehaus.plexusgroupId>
                    <artifactId>plexus-compiler-apiartifactId>
                    <version>2.8.1version>
                dependency>
                <dependency>
                    <groupId>org.projectlombokgroupId>
                    <artifactId>lombokartifactId>
                    <version>${lombok.version}version>
                dependency>
            dependencies>
        plugin>
    plugins>
build>

以上问题得到解决

maven打包异常

  • 无法解析lombok的@Data的注解。Groovy:unable to resolve class Delegate , unable to find class for annotation
    需要使用groovy-eclipse-compiler插件打包
  • The import XXX cannot be resolved
    被依赖的子模块使用了spring-boot-maven-plugin打包插件,导致引用模块无法发现公用模块的包文件

你可能感兴趣的:(maven)