如何将Javadoc JAR文件添加到IntelliJ IDEA中的Maven项目?

huangapple go评论67阅读模式
英文:

How to add a Javadoc JAR file to a Maven project in IntelliJ IDEA?

问题

以下是您要翻译的内容:

我正在制作一个本地的Java实用库,并将其构建成一个JAR文件。我还为Javadocs构建了一个JAR文件。

这些是由Maven生成的JAR文件:

如何将Javadoc JAR文件添加到IntelliJ IDEA中的Maven项目?

现在,我正在尝试在IntelliJ IDEA中使用Javadocs JAR文件,通过在“文件”>“项目结构”中导入它,它可以工作。我可以在我的IDE中获得有关代码引用的提示和文档。但是,一旦我重新加载我的Maven项目,Javadocs就消失了,我必须手动添加它。

我还从IntelliJ那里得到了一个警告,每次我重新添加Javadoc JAR文件时都会出现。

如何将Javadoc JAR文件添加到IntelliJ IDEA中的Maven项目?

添加Javadoc JAR文件到Maven项目的正确方式是什么?

英文:

I am making a local Java utility library and building it into a JAR file. I am also building a JAR file for the Javadocs.

These are the JAR files generated by Maven:

如何将Javadoc JAR文件添加到IntelliJ IDEA中的Maven项目?

Now, I am trying to use the Javadocs JAR file with IntelliJ IDEA by importing it in File > Project Structure, and it works. I get hints and documentation for code references in my IDE. But as soon as I reload my Maven project, the Javadocs are gone and I have to manually add it back.

I am also getting this warning from IntelliJ everytime I add the Javadoc JAR file back.

如何将Javadoc JAR文件添加到IntelliJ IDEA中的Maven项目?

What is the proper way of adding a Javadoc JAR file into a Maven project?

答案1

得分: 4

Pure Maven(好的IDE应该识别这些):

mvn dependency:resolve -Dclassifier=javadoc

Ref: https://maven.apache.org/plugins/maven-dependency-plugin/resolve-mojo.html

Notes: It's rather unusual (unless explicitly ordered) to "package" (dependency) javadocs with the main artifact... In maven, "we" rather maintain (own!) artifacts for "main"/sources/and javadocs (See: https://maven.apache.org/repository/guide-central-repository-upload.html)

As mentioned, good IDEs should be capable of processing the "local repository" for javadoc (and source) artifacts of undrlying dependencies.

To "download sources" use:

mvn dependency:sources

Ref: https://maven.apache.org/plugins/maven-dependency-plugin/sources-mojo.html 如何将Javadoc JAR文件添加到IntelliJ IDEA中的Maven项目?


When your (remote) Repository does not comply with "central requirements" (has no "source" and "javadoc" artifacts attached), also to eliminate (any) <scope>system</scope> dependency, I would strongly recommend (to "mavenize" the dependencies and) install/deploy sources and javadocs artifacts for this:

  • locally with: mvn install:install ...
  • to a "repo": mvn deploy:...

For "mavenize" refer to:

Specifically for sources and javadocs artifacts (once you have/generate these):


The "pure IDE" way would be to link to the (external!) sources/javadocs (in file system/zip/jar archive):
... See screenshot:

如何将Javadoc JAR文件添加到IntelliJ IDEA中的Maven项目?

  • com.example:my-dep:0.0.1-SNAPSHOT is my (fake) system scoped dependency.
  • After "applying" changes and confirming the warn dialog (iml vs pom, re-import...), IntelliJ should recognize javadocs and sources.
  • According to the warning, our "modifications" get lost in case of a "maven re-import".
英文:

Pure Maven (good IDEs should recognize these):

mvn dependency:resolve -Dclassifier=javadoc

Ref: https://maven.apache.org/plugins/maven-dependency-plugin/resolve-mojo.html

Notes: It's rather unusual (unless explicitly ordered) to "package" (dependency) javadocs with the main artifact... In maven, "we" rather maintain (own!) artifacts for "main"/sources/and javadocs (See: https://maven.apache.org/repository/guide-central-repository-upload.html)

As mentioned, good IDEs should be capable of processing the "local repository" for javadoc (and source) artifacts of undrlying dependencies.

To "download sources" use:

mvn dependency:sources

Ref: https://maven.apache.org/plugins/maven-dependency-plugin/sources-mojo.html 如何将Javadoc JAR文件添加到IntelliJ IDEA中的Maven项目?


When your (remote) Repository does not comply with "central requirements" (has no "source" and "javadoc" artifacts attached),
also to eliminate (any) &lt;scope&gt;system&lt;/scope&gt; dependency, I would strongly recommend (to "mavenize" the dependencies and) install/deploy sources and javadocs artifacts for this:

  • locally with: mvn install:install ...
  • to a "repo": mvn deploy:...

For "mavenize" refer to:

Specifically for sources and javadocs artifacts (once you have/generate these):


The "pure IDE" way, would be to link to the (external!) sources/javadocs (in file system/zip/jar archive):
... See screenshot:

如何将Javadoc JAR文件添加到IntelliJ IDEA中的Maven项目?

  • com.example:my-dep:0.0.1-SNAPSHOT is my (fake) system scoped dependency.

  • After "applying" changes and confirming the warn dialog (iml vs pom, re-import...), IntelliJ should recoginze javadocs and sources.

  • According to the warning our "modifications" get lost in case of a "maven re-import".

答案2

得分: 2

以下是翻译好的部分:

有一种更通用的 Maven 风格的方式,应该优先使用,而不是 "IDE 方式"。您可以在项目内部使用一个本地的 "伪" 仓库。将 JAR 文件添加到您的仓库中。Maven 命令的具体形式取决于 JAR 文件的类型。

JAR 文件:

mvn deploy:deploy-file \
  -DgroupId=org.example \
  -DartifactId=mylib\
  -Dversion=1.1 \
  -Dfile=/path/to/mylib-1.1.jar \
  -Dpackaging=jar \
  -Durl=file://path/to/your-project/fake-repo

源代码:

mvn deploy:deploy-file \
  -DgroupId=org.example \
  -DartifactId=mylib\
  -Dversion=1.1 \
  -Dfile=/path/to/mylib-1.1-sources.jar \
  -Dpackaging=jar \
  -Durl=file://path/to/your-project/fake-repo \
  -Dclassifier=sources

Javadoc 文档:

mvn deploy:deploy-file \
  -DgroupId=org.example \
  -DartifactId=mylib\
  -Dversion=1.1 \
  -Dfile=/path/to/mylib-1.1-javadoc.jar \
  -Dpackaging=jar \
  -Durl=file://path/to/your-project/fake-repo \
  -Dclassifier=javadoc

接下来的步骤是将仓库和依赖项添加到您的 POM 文件中:

<repositories>
  <repository>
    <id>fake-repo</id>
    <name>Just a fake repository.</name>
    <url>file://${project.basedir}/fake-repo</url>
  </repository>
</repositories>

<dependencies>
  <dependency>
    <groupId>org.example</groupId>
    <artifactId>mylib</artifactId>
    <version>1.1</version>
  </dependency>
</dependencies>
英文:

There is a more general maven-style way and should be preferred over the "IDE way". You can use a local "fake" repository inside your project. Add the jar files to your repo. The maven call depends on the type of the jar.

The jar:

mvn deploy:deploy-file \
  -DgroupId=org.example \
  -DartifactId=mylib\
  -Dversion=1.1 \
  -Dfile=/path/to/mylib-1.1.jar \
  -Dpackaging=jar \
  -Durl=file://path/to/your-project/fake-repo

The sources:

mvn deploy:deploy-file \
  -DgroupId=org.example \
  -DartifactId=mylib\
  -Dversion=1.1 \
  -Dfile=/path/to/mylib-1.1-sources.jar \
  -Dpackaging=jar \
  -Durl=file://path/to/your-project/fake-repo \
  -Dclassifier=sources

The javadoc:

mvn deploy:deploy-file \
  -DgroupId=org.example \
  -DartifactId=mylib\
  -Dversion=1.1 \
  -Dfile=/path/to/mylib-1.1-javadoc.jar \
  -Dpackaging=jar \
  -Durl=file://path/to/your-project/fake-repo \
  -Dclassifier=javadoc

The next step is adding the repo and the dependency to your pom:

&lt;repositories&gt;
  &lt;repository&gt;
    &lt;id&gt;fake-repo&lt;/id&gt;
    &lt;name&gt;Just a fake repository.&lt;/name&gt;
    &lt;url&gt;file://${project.basedir}/fake-repo&lt;/url&gt;
  &lt;/repository&gt;
&lt;/repositories&gt;

&lt;dependencies&gt;
  &lt;dependency&gt;
    &lt;groupId&gt;org.example&lt;/groupId&gt;
    &lt;artifactId&gt;mylib&lt;/artifactId&gt;
    &lt;version&gt;1.1&lt;/version&gt;
  &lt;/dependency&gt;
&lt;/dependencies&gt;

huangapple
  • 本文由 发表于 2023年5月21日 23:48:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/76300711.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定