有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java获取Eclipse上快照依赖项的源代码

有些事让我很烦恼。。。 在一个有很多依赖项的大型项目中,其中一些在Maven2中被设置为快照

问题是,如果不加载项目或修复对上一版本的依赖关系,我似乎无法通过Eclipse获得源代码。 对于调试来说,这真的很烦人

编辑

这是我在eclipse maven控制台中得到的:

26/08/10 11:31:46 CEST: Downloading http://repo-maven/archiva/repository/snapshots/com/blabla/1.1-SNAPSHOT/blabla-1.1-20100824.213711-80-javadoc.jar
26/08/10 11:31:47 CEST: Could not download sources for com.blabla:blabla:1.1-20100824.213711-80

在archiva上,我可以看到我想在eclipse中检索的已部署内容

Repository   snapshots
Group ID  com.blabla
Artifact ID  blabla
Version  1.1-20100824.213711-80
Packaging  jar
Parent  com.blabla bla 1.1-SNAPSHOT (View)
Other Versions  1.1-20100824.213535-79

我可以用浏览器下载这个工件的源代码,但不能在Eclipse中下载。。。知道吗


共 (1) 个答案

  1. # 1 楼答案

    The matter is that it seems I can't get the sources through Eclipse without loading the project or fixing the dependency to the last release. For debugging, it's really annoying me...

    嗯,这些模块可能没有将源JAR发布为“常规”构建过程的一部分(即在发行版之外)。如果这些模块在您的控制之下(据我所知),那么配置Maven Source Plugin为它们生成源jar并在公司回购协议中部署它们应该可以解决问题。从Usage页面:

    Installing the sources along with your artifact

    There are two ways to do this. You can either bind this plugin to a phase or you can add it to a profile. The goals source:jar-no-fork and source:test-jar-no-fork are preferred for binding the goal to the build lifecycle.

    Installing the sources using a phase binding

    Here is how you would configure the plugin in your pom.xml to run automatically during the verify phase:

    <project>
      ...
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
            <version>2.1.2</version>
            <executions>
              <execution>
                <id>attach-sources</id>
                <phase>verify</phase>
                <goals>
                  <goal>jar-no-fork</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
      ...
    </project>
    

    We are using the verify phase here because it is the phase that comes before the install phase, thus making sure that the sources jar has been created before the install takes place.

    Installing the sources using a profile

    If you want to install a jar of your sources along with your artifact during the release process, you can add this to your pom.xml file:

    <project>
      ...
      <profiles>
        <profile>
          <id>release</id>
          <build>
            <plugins>
              <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.1.2</version>
                <executions>
                  <execution>
                    <id>attach-sources</id>
                    <goals>
                      <goal>jar-no-fork</goal>
                    </goals>
                  </execution>
                </executions>
              </plugin>
            </plugins>
          </build>
        </profile>
      </profiles>
      ...
    </project>
    

    使用概要文件可能是一个好主意,这样构建源JAR将只由运行在CI服务器级别的构建完成,而不是在开发人员机器上完成