简体   繁体   English

如果使用注释,如何使Maven构建失败?

[英]How to fail maven build if annotation used?

I want to forbid usage of some annotations in a project. 我想禁止在项目中使用某些注释。 Specially @SneakyThrows annotation from lombok . 从特别@SneakyThrows注释龙目岛 One way to do this is to fail while building maven artifact. 一种方法是在构建Maven工件时失败。 Are there some existing plugins to reach this? 是否有一些现有的插件可以达到此目的?

I think it is possible to achive using static code analyzers like checkstyle . 我认为可以使用诸如checkstyle之类的静态代码分析器来实现。 But I don't want to write new rule for it. 但是我不想为此写新规则。

Also it is interesting if exists such plugins for gradle? 同样有趣的是是否存在这样的gradle插件?

        <plugin>
            <groupId>com.google.code.maven-replacer-plugin</groupId>
            <artifactId>replacer</artifactId>
            <version>1.5.3</version>
            <executions>
                <execution>
                    <phase>process-sources</phase>
                    <goals>
                        <goal>replace</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <basedir>${basedir}</basedir>
                <includes>
                    <include>target/**/*.java</include>
                </includes>
                <regex>false</regex>
                <replacements>
                    <replacement>
                        <token>@SneakyThrows</token>
                        <value>@@@@ I-DONT-THINK-SO @@@@</value>
                    </replacement>
                </replacements>
            </configuration>
        </plugin>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM