kotlin - 如何从 Kotlin AllOpen 插件中排除注释?

标签 kotlin axon kotlin-maven-plugin

我正在使用 Axon 框架,我可以在其中注释我的 域名 @Aggregate 的类(class)(使用 Spring 中的 @Component 进行元注释)。然后我必须通过标记 final 来为我拥有的每个私有(private)方法/字段道歉明确地。

我认为在我的情况下,我很擅长将类(class)标记为打开,所以我想手动进行,同时排除 @Aggregate来自 spring插件,但我找不到这样做的方法。

最佳答案

解决方法
根据documentation , spring插件使用 all-open只需列出 Spring 注释,同时支持元注释。所以,我们就是这样做的,但我们没有指定列表 @Component ,所以在我们的代码中,我们必须使用原型(prototype)(存储库、服务等)。这样它就不会接收 @Aggregate :

<plugin>
    <groupId>org.jetbrains.kotlin</groupId>
    <artifactId>kotlin-maven-plugin</artifactId>
    <version>${kotlin.version}</version>
    <configuration>
        <compilerPlugins>
            <!-- instead of 'spring' -->
            <plugin>all-open</plugin>
        </compilerPlugins>
        <pluginOptions>
            <!-- todo check up on https://stackoverflow.com/questions/56537496 -->
            <!-- listing all spring annotations except @Component -->
            <option>all-open:annotation=org.springframework.stereotype.Service</option>
            <option>all-open:annotation=org.springframework.stereotype.Controller</option>
            <option>all-open:annotation=org.springframework.data.repository.Repository</option>
            <option>all-open:annotation=org.springframework.context.annotation.Configuration</option>
            <option>all-open:annotation=org.springframework.boot.test.context.SpringBootTest</option>
            <option>all-open:annotation=org.springframework.cache.annotation.Cacheable</option>
            <option>all-open:annotation=org.springframework.transaction.annotation.Transactional</option>
            <option>all-open:annotation=org.springframework.scheduling.annotation.Async</option>
        </pluginOptions>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-maven-allopen</artifactId>
            <version>${kotlin.version}</version>
        </dependency>
    </dependencies>
</plugin>

关于kotlin - 如何从 Kotlin AllOpen 插件中排除注释?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56537496/

相关文章:

python - Firebase ML Kit 使用自定义 TFLITE 为 Android 上的不同输出产生相同的推理

unit-testing - 在Kotlin中模拟http响应

kotlin - Reactor-加载分页API的所有页面

kotlin - 父类的init block 中的null值

java - CQRS 架构中的条件 `create` 命令

testing - 轴突框架 : How to test @EventHandler

java - Axon 框架与 Atomikos?工作怎么样?

maven - Kapt 无法与 OpenJDK 16 一起正常工作