我在habarta typescript generator上遇到了问题,尝试了2.7以上的所有版本。到最新。这是gradle buildscript
generateTypeScript {
jsonLibrary = 'jackson2'
classPatterns = [
'com.foo.**'
]
excludeClasses = [
'org.springframework.data.mongodb.repository.ReactiveMongoRepository'
]
excludeClassPatterns = [
'java.io.Serializable',
'com.foo.**Repository',
'com.foo.**Builder',
'org.springframework.data.mongodb.repository.**',
'java.lang.Compareable',
'org.bson.types.ObjectId'
]
outputFile = 'build/customers.d.ts'
outputKind = 'global'
namespace = 'Customers'
optionalProperties = 'all'
customTypeMappings = [
'java.time.LocalDateTime:string',
'org.bson.types.ObjectId:string'
]
}
错误是
Unable to load class 'org.springframework.data.mongodb.repository.ReactiveMongoRepository'.
找不到的类在类路径上,编译项目可以正常进行。在excludeClasses或excludeClassPatterns中省略该类没有什么区别。
所有应转换的类(来自classPatterns + excludeedClasses(Patterns)的规则)均未实现ReactiveMongoRepository。
我做错了什么以及如何解决呢?
Stacktrace
* What went wrong:
Execution failed for task ':generateTypeScript'.
> org/springframework/data/mongodb/repository/ReactiveMongoRepository
* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':generateTypeScript'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:110)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:77)
at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:59)
at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:59)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:101)
at org.gradle.api.internal.tasks.execution.FinalizeInputFilePropertiesTaskExecuter.execute(FinalizeInputFilePropertiesTaskExecuter.java:44)
at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:91)
at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:62)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:59)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.run(EventFiringTaskExecuter.java:51)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:317)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:309)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:185)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:97)
at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:46)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$ExecuteTaskAction.execute(DefaultTaskExecutionGraph.java:262)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$ExecuteTaskAction.execute(DefaultTaskExecutionGraph.java:246)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:136)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:130)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.execute(DefaultTaskPlanExecutor.java:201)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.executeWithTask(DefaultTaskPlanExecutor.java:192)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:130)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
Caused by: java.lang.NoClassDefFoundError: org/springframework/data/mongodb/repository/ReactiveMongoRepository
at cz.habarta.typescript.generator.Input.loadClasses(Input.java:150)
at cz.habarta.typescript.generator.Input.fromClassNames(Input.java:136)
at cz.habarta.typescript.generator.Input.fromClassNamePatterns(Input.java:131)
at cz.habarta.typescript.generator.Input.fromClassNamesAndJaxrsApplication(Input.java:55)
at cz.habarta.typescript.generator.gradle.GenerateTask.generate(GenerateTask.java:184)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
at org.gradle.api.internal.project.taskfactory.StandardTaskAction.doExecute(StandardTaskAction.java:46)
at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:39)
at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:26)
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:794)
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:761)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:131)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:317)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:309)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:185)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:97)
at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:120)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:99)
... 30 more
Caused by: java.lang.ClassNotFoundException: org.springframework.data.mongodb.repository.ReactiveMongoRepository
... 52 more
build.grade:
buildscript {
ext {
springBootVersion = '2.0.6.RELEASE'
}
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath 'cz.habarta.typescript-generator:typescript-generator-gradle-plugin:2.8.449'
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'cz.habarta.typescript-generator'
group = 'com.foo'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 10
repositories {
mavenCentral()
jcenter()
}
generateTypeScript {
jsonLibrary = 'jackson2'
classPatterns = [
'com.foo.**'
]
excludeClasses = [
'org.springframework.data.mongodb.repository.ReactiveMongoRepository'
]
excludeClassPatterns = [
'java.io.Serializable',
'com.foo.**Repository',
'com.foo.**Builder',
'org.springframework.data.mongodb.repository.**',
'java.lang.Compareable',
'org.bson.types.ObjectId'
]
outputFile = 'build/customers.d.ts'
outputKind = 'global'
namespace = 'Customers'
optionalProperties = 'all'
customTypeMappings = [
'java.time.LocalDateTime:string',
'org.bson.types.ObjectId:string'
]
}
task copyTypescriptTypes(type: Copy) {
from file('build/customers.d.ts')
into file('/frontend/src')
}
task buildAndCopy() {
dependsOn generateTypeScript
dependsOn copyTypescriptTypes
tasks.findByName('copyTypescriptTypes').mustRunAfter 'generateTypeScript'
}
dependencies {
implementation 'org.passay:passay:1.4.0'
implementation 'com.neovisionaries:nv-i18n:1.23'
implementation('org.springframework.boot:spring-boot-starter-actuator')
implementation('org.springframework.boot:spring-boot-starter-data-jpa')
implementation('org.springframework.boot:spring-boot-starter-data-mongodb-reactive')
implementation('org.springframework.boot:spring-boot-starter-data-redis-reactive')
implementation('org.springframework.boot:spring-boot-starter-jdbc')
implementation('org.springframework.boot:spring-boot-starter-security')
implementation('org.springframework.boot:spring-boot-starter-web')
implementation('org.springframework.session:spring-session-data-redis')
implementation('org.springframework.session:spring-session-jdbc')
runtimeOnly('mysql:mysql-connector-java')
compileOnly('org.projectlombok:lombok')
testImplementation('org.springframework.boot:spring-boot-starter-test')
testImplementation('io.projectreactor:reactor-test')
testImplementation('org.springframework.security:spring-security-test')
compile "javax.xml.bind:jaxb-api:2.2.11"
compile "com.sun.xml.bind:jaxb-core:2.2.11"
compile "com.sun.xml.bind:jaxb-impl:2.2.11"
compile "javax.activation:activation:1.1.1"
}
失败的课程:
public class UserData {
@Id
private ObjectId id;
@CreatedDate
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)
private LocalDateTime createdAt;
@LastModifiedDate
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)
private LocalDateTime updatedAt;
private String email;
}
错误:
Unable to load class 'org.bson.types.ObjectId'.
答案 0 :(得分:1)
因此,答案似乎是您对该ReactiveMongoRepository
接口具有依赖性。
在不依赖ReactiveMongoRepository
的情况下尝试进行项目设置,运行generateTypeScript
可以得到一个清晰的构建。
但是,当取决于该接口时,该错误与您发布的内容匹配(请参见下文)。
扩展ReactiveMongoRepository
,然后将其标记为已排除是行不通的,并且在这种情况下是无意义的。
java.lang.NoClassDefFoundError: org/springframework/data/mongodb/repository/ReactiveMongoRepository
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)
...
显然,org.bson.types.ObjectId
不能排除,因为您正在UserData
中使用它。
要解决Jackson和Bson错误,您只需要将它们作为依赖项即可。
到目前为止,它们仅可通过传递依赖关系使用,传递依赖关系可能是重新打包的版本。
compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: '2.9.8'
compile group: 'org.mongodb', name: 'bson', version: '3.10.1'