visualkhh
3k
2019-10-26 19:35:06
0
438

java model class -> typescript type generator


안녕하세요

요즘 front 작업을 거의 typescript (angular)로 하고있습니다.

그래서 자바의 모델클래스를 typescript type으로 매번 추가해주는게 번거러웠는데. 좋은 gradle plugin있어 공유합니다.


build.gradle


buildscript {
ext {
springBootVersion = '1.5.10.RELEASE'
}
repositories {
mavenCentral()
maven {
url "http://maven.omnicns.co.kr/nexus/content/repositories/releases/"
}
maven {
url 'https://plugins.gradle.org/m2/'
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath 'cz.habarta.typescript-generator:typescript-generator-gradle-plugin:2.+'
classpath 'cz.habarta.typescript-generator:typescript-generator-spring:2.+'

}
}

allprojects {

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'

apply plugin: 'io.spring.dependency-management'

apply plugin: 'cz.habarta.typescript-generator'

...
repositories {
mavenCentral()
maven { url "https://repository.jboss.org/nexus/content/repositories/releases" }
maven { url "http://maven.omnicns.co.kr/nexus/content/repositories/releases/" }
}

dependencies {
compile('...')

}

}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'


group = 'com.s.omnifit2'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

springBoot {
executable = true
}
bootRepackage {
mainClass = 'com.omnicns.medicine.MedicineApplication'
}
...

processResources {
dependsOn generateTypeScript
}

def webappDir = "$projectDir/src/main/resources/webapp"
def templatesDir = "$projectDir/src/main/resources/templates"
def angularDir = "$projectDir/front"


generateTypeScript {


customTypeNaming = [
'org.springframework.security.core.userdetails.UserDetails:UserDetailsOfSpring',
'com.s.medicine.domain.security.Auth:UserDetailAuth'
]

classPatterns = [
'com.s.medicine.domain.*',
'com.s.medicine.domain.security.*',
'com.s.medicine.model.*',
'com.s.medicine.model.error.*',
'com.s.medicine.model.api.*',
'com.s.medicine.model.msg.*',
]
outputFileType = 'implementationFile'
jsonLibrary = 'jackson2'
outputKind = 'module'
outputFile = "${angularDir}/src/app/model/commomModels.ts"
scanSpringApplication = true
generateSpringApplicationClient = true

}

1
1
  • 댓글 0

  • 로그인을 하시면 댓글을 등록할 수 있습니다.