跳至主要內容

ihub-java

Henry...大约 2 分钟

ihub-java

插件说明

ihub-java插件用于集成Java相关插件环境、配置一些默认依赖以及兼容性配置

信息描述
插件IDpub.ihub.plugin.ihub-java
插件名称Java插件
插件类型Project[1]
扩展名称iHubJava
插件依赖ihub-bomjavaopen in new windowjava-libraryopen in new windowlombokopen in new windowproject-reportopen in new windowbuild-dashboardopen in new window
net.bytebuddy.byte-buddy-gradle-pluginopen in new windoworg.springdoc.openapi-gradle-pluginopen in new window

启用JMoleculesPlugin插件时,org.gradle.parallel设置false,可以消除prepareKotlinBuildScriptModel任务警告

扩展属性

ExtensionDescriptionDefaultExt[2]Prj[3]Sys[4]Env[5]
defaultDependencies默认依赖(“,”分割)详见,可以设置false关闭默认配置log
compileEncodingJava编译编码UTF-8
sourceCompatibilityJava Source 兼容性配置
targetCompatibilityJava Target 兼容性配置
gradleCompilationIncrementalgradle增量编译true
compilerArgs编译扩展属性,多个参数用空格分隔,如:-parameters -Xlint:unchecked
jvmArgsJVM扩展属性,多个参数用空格分隔,如:-XX:+UseG1GC -Xms128m -Xmx512m
jmoleculesArchitectureJMolecules架构(可选类型:cqrs、layered、onion)详见open in new windowonion

注意

由于插件会在beforeEvaluate阶段处理一些配置,根项目时不会处理这个阶段,Ext[2:1]配置可能会失效,建议优先使用Prj[3:1]配置

插件安装

Kotlin
plugins {
    id("pub.ihub.plugin.ihub-java")
}

配置示例

Kotlin
iHubJava {
    defaultDependencies.set("jaxb,log,doc,mapstruct,jmolecules")
    compatibility.set("11")
}

默认依赖

jaxb:添加jaxb运行时依赖配置。

DependencyTypeDependencies
excludecom.sun.xml.bind:jaxb-core
runtimeOnlyjavax.xml.bind:jaxb-api
runtimeOnlyorg.glassfish.jaxb:jaxb-runtime

log:添加默认日志依赖配置。

DependencyTypeDependencies
excludecommons-logging:commons-logging
excludelog4j:log4j
excludeorg.apache.logging.log4j:log4j-core
excludeorg.slf4j:slf4j-log4j12
excludeorg.slf4j:slf4j-jcl
runtimeOnlyorg.slf4j:jul-to-slf4j
runtimeOnlyorg.slf4j:log4j-over-slf4j
runtimeOnlyorg.slf4j:jcl-over-slf4j
implementationorg.slf4j:slf4j-api

mapstruct:添加添加MapStruct依赖配置。

DependencyTypeDependencies
implementationorg.mapstruct:mapstruct
annotationProcessororg.mapstruct:mapstruct-processor

doc:添加Doc注解依赖。

DependencyTypeDependencies
compileOnlyio.swagger.core.v3:swagger-annotations
annotationProcessorpub.ihub.lib:ihub-process-doc

jmolecules:添加jMolecules依赖。

DependencyTypeDependencies
implementationorg.jmolecules:jmolecules-ddd
implementationorg.jmolecules:jmolecules-events
implementationorg.jmolecules:jmolecules-cqrs-architecture(optional)
implementationorg.jmolecules:jmolecules-layered-architecture(optional)
implementationorg.jmolecules:jmolecules-onion-architecture(optional)

jmolecules-integrations:添加jMolecules-integrations依赖。

DependencyTypeDependencies
implementationorg.jmolecules.integrations:jmolecules-spring
implementationorg.jmolecules.integrations:jmolecules-jpa
implementationorg.jmolecules.integrations:jmolecules-jackson
testImplementationorg.jmolecules.integrations:jmolecules-archunit

默认配置

由于Lombok插件6.1.0之后不再自动生成lombok.config文件详见open in new window当本地没有lombok.config时,会自动生成如下配置:

config.stopBubbling = true
lombok.addLombokGeneratedAnnotation = true

配置Jar属性

属性
Implementation-Title{project.name}
Automatic-Module-Name{project.name}
Implementation-Version{project.version}
Implementation-Vendor-Id{project.group}
Created-ByJava + 当前Java主版本号

生成配置如下:

Manifest-Version: 1.0
Implementation-Title: ihub-plugins
Automatic-Module-Name: ihub.plugins
Implementation-Version: 1.0.0
Implementation-Vendor-Id: pub.ihub.plugin
Created-By: Java 11

可以通过compatibility配置兼容性。

可选功能配置

registerFeature:支持配置可选功能,详见open in new window

FieldDependencies
feature功能
capabilities能力

配置示例

Kotlin
iHubJava {
    registerFeature("servlet", "cloud-support", "servlet-support")
    registerFeature("reactor", "cloud-support", "reactor-support")
}
dependencies {
    "servletApi"("org.springframework.boot:spring-boot-starter-web")
    "reactorApi"("org.springframework.boot:spring-boot-starter-webflux")
}

  1. Project:项目类型插件,配置于build.gradle文件,类型说明详见open in new window ↩︎

  2. Ext(Extension):插件自定义扩展属性,配置于build.gradle文件,配置方式详见 ↩︎ ↩︎

  3. Prj(Project):项目属性,配置于gradle.properties文件,配置格式扩展名.属性名详见 ↩︎ ↩︎

  4. Sys(System):系统属性,如命令行传递的信息等,配置格式扩展名.属性名详见 ↩︎

  5. Env(Environment):环境变量属性,配置格式全部大写,多个单词,用_分隔详见 ↩︎