gpt4 book ai didi

java - habarta typescript 插件无法加载类

转载 作者:行者123 更新时间:2023-12-02 10:11:45 25 4
gpt4 key购买 nike

我的 habarta typescript generator 有问题,尝试了从2.7开始的所有版本。到最新的。这是 gradle 构建脚本

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'
]
}

错误是

无法加载类“org.springframework.data.mongodb.repository.ReactiveMongoRepository”。

找不到的类位于类路径中,编译项目工作正常。在 exceptClasses 或 exceptClassPatterns 中省略该类并没有什么区别。

应转换的类(来自 classPatterns + exceptedClasses(Patterns) 的规则)均未实现 ReactiveMongoRepository。

我做错了什么以及如何解决这个问题?

堆栈跟踪

* 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

构建.等级:

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'.

最佳答案

所以,答案似乎是您依赖于该ReactiveMongoRepository接口(interface)。

尝试您的项目设置,而不依赖于 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'

关于java - habarta typescript 插件无法加载类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54958422/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com