5

未使用の依存関係を検出するために利用している mvn プロジェクトでは、Google の AutoValue () に指定できるmaven-dependency-plugin依存関係はないように見えます。これにより、パッケージからの注釈が使用されているにもかかわらず、依存関係が使用されていることをプラグインに納得させることができます。が使用され (例: )、が除外されている場合、プロジェクトはビルドされません。scopecom.google.auto.value:auto-value@AutoValueauto-value

1 つの解決策は、プラグインに構成エントリを追加するだけです。

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <configuration>
        <usedDependencies>
            <usedDependency>com.google.auto.value:auto-value</usedDependency>
        </usedDependencies>
    </configuration>
</plugin>

しかし、注釈ごとに依存関係の使用を検出する方法で、maven-dependency-pluginまたはdependencyエントリのいずれかを構成できるかどうか知りたいですか?auto-value

RetentionPolicy私の疑いは、自動値から使用している注釈がRetentionPolicy.SOURCEコンパイラによって破棄されているため、これは不可能であるということです。これは正しいです?

4

1 に答える 1

5

残念ながら、あなたの疑いは正しいです。maven-dependency-pluginドキュメントには、これがソースレベルの注釈に関する懸念事項として具体的に記載されています: http://maven.apache.org/shared/maven-dependency-analyzer/

警告: 分析はソースではなくバイトコード レベルで行われます。その場合、検出されないケース (定数、ソースのみを保持する注釈、javadoc 内のリンク) があり、それらが依存関係の唯一の使用である場合、誤った結果につながる可能性があります。

例のように強制するか、代わりに構成を使用AutoValueできますused(これは私が最近行ったことです)。usedDependenciesignoredUnusedDeclaredDependencies

I don't believe it is possible to configure the dependency section to avoid this because maven doesn't provide a scope level that is compile only. I mark AutoValue with the provided scope to keep it out of any shaded jars I might make.

Lastly, you could write (or find if it exists) a custom dependency analyzer that takes source level annotations into account. See the documentation here http://maven.apache.org/plugins/maven-dependency-plugin/analyze-mojo.html#analyzer. Probably not worth the effort.

于 2016-08-01T22:21:36.230 に答える