java - 通过 Maven 或 Eclipse 使用和检查 Android 支持注释(无需 Android Studio)

标签 java android eclipse maven annotations

我想在 Java/Maven 项目中使用 Google 的 Android 支持注释库 ( http://tools.android.com/tech-docs/support-annotations ) 提供的一些有用注释。 我希望使用 mvn 在编译时验证注释或 Eclipse,无需求助于 Android Studio。 这可能吗?

我我的pom.xml我已经添加了以下内容:

    <dependency>
        <groupId>com.android.support</groupId>
        <artifactId>support-annotations</artifactId>
        <version>23.0.0</version>
        <scope>provided</scope>
    </dependency>

我目前没有使用 android-maven-plugin因为它只是一个简单的 jar,不依赖其他 Android 库。声明依赖关系允许我在代码中使用注释。例如:

import android.support.annotation.CallSuper;
import android.support.annotation.NonNull;

public class TestAnnot
{

    @CallSuper
    public void blah() { }

    public void bleh(@NotNull String str) { }

}

这在 Eclipse 和 mvn 中都可以很好地编译。 。然而,任何一方都没有标记明显违反注释规则的行为。例如,目前没有什么可以阻止我这样做:

public class SubTestAnnot
{
    @Overrides
    public void blah()
    {
        // not calling super.blah() even though I should
        bleh(null); // calling bleh(String) with null even though that's not allowed
    }

}

我查看了该库的源代码(查看 <Android SDK path>/extras/android/m2repository/com/android/support/support-annotations/23.0.0 ),但它似乎只声明了注释本身,但没有代码来验证它们。所以我假设 Google 已经单独实现了这一点,也许是在 SDK 组件之一中?

那么,有谁知道如何配置 Maven 和/或 eclipse 来实际检查这些注释?

最佳答案

来自here在“强制注释”下

When you're using Android Studio and IntelliJ, the IDE will flag calls where you are passing the wrong type of parameter to methods annotated with these annotations.

As of version 1.3.0-beta1 of the Gradle plugin, and with the Android M Preview platform tools installed, these checks are also checked/enforced on the command line by the "lint" gradle task. This is useful if you want to flag problems as part of your continuous integration server. NOTE: That does not incude the nullness annotations. All the other annotations in this document are checked by lint.)

关于java - 通过 Maven 或 Eclipse 使用和检查 Android 支持注释(无需 Android Studio),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32567371/

相关文章:

java - 如何在mockito中模拟enum.values()

android - 将库上传到 Bintray,但使用时无法解析

android - 停止重复计时器android

eclipse - org.classpath.icedtea.pulseaudio.* 的来源在哪里?

c - 如何将已编译库的源路径链接到 Eclipse 中的不同位置?

eclipse - 使用 excel 数据源在 tomcat 中部署 birt 查看器

java - 更新 Gradle 项目库

java - Byte Buddy - 方法 Implementation.Context.Default 不是 bean 属性 - 创建一个 setter

java - 是否有规范将 INBOX 定义为主文件夹?

android - 带有自定义数据源的分页库在房间更新时不更新行