开发者

How to add the source from another dependency in Maven?

开发者 https://www.devze.com 2023-03-18 05:18 出处:网络
I\'m doing some tests with Spring 2.0.8. I\'ve the following problem, all the source code is downloaded with the \"spring\" artifact, but is not attached by mvn eclipse:eclipse to the other artifacts,

I'm doing some tests with Spring 2.0.8. I've the following problem, all the source code is downloaded with the "spring" artifact, but is not attached by mvn eclipse:eclipse to the other artifacts, for instance for "spring-aop" art开发者_JS百科ifact, I can't access source from Eclipse, despite the aop package is present in spring-2.0.8-sources.jar.

<properties>
    <org.springframework.version>2.0.8</org.springframework.version>
</properties>
<dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
</dependencies>

If I add the spring-2.0.8-sources.jar manually to spring-aop in Java Build Path, then I can navigate the source code from Eclipse, but I was wondering how to tell Maven to do that, since every time I add or change a library, I'd have to repeat the attach source operation.

UPDATE: My original fear of having the configuration overwritten proved wrong. Both m2eclipse and "mvn eclipse:eclipse" don't overwrite manual changes to the configuration. I am still interested to know if it's possible to tell Maven to attach sources from another dependency. I've also a Nexus installation, if that can help.


As @Will Iverson says, recent m2eclipse plugins can download sources automatically, either ahead-of-time, or on-demand. The m2eclipse has been able to do this for quite a long time.

If this is not working:

  • check you have an up-to-date plugin (and an up-to-date Eclipse!),
  • look at the way that the plugin is configured,
  • check Eclipse's effective web proxy configuration,
  • check ~/.m2/settings.xml to see if you are using a maven proxy repository,
  • if you are using a proxy repository, check the repository configs to see if it is serving source JARs.

If I understand, when I add a dependency, you're suggesting that I should do m2Maven > Update Dependencies, m2Maven > Download JavaDoc, m2Maven > Download Sources, and this operation, despite being more inconvenient of calling "mvn eclipse:eclipse", will preserve my manual changes, instead of overwriting them.

  1. If you are using m2eclipse, you should need to use "mvn eclipse:eclipse". Instead you just import the maven project using (for example) File > Import > Maven > Existing Maven Project.

  2. I don't think this will destroy your existing hand-created project settings ... assuming that you haven't accidentally checked them into SCM or something.

  3. If you are concerned about the possibility of losing settings, make a backup copy of your workspace; e.g. cp -r ... or tar cf ...

  4. Maven allows you to import direct from SCM in one step. That's surely more convenient than mvn eclipse:eclipse ... and it gives you the benefits of the m2eclipse plugin.


The problem, I think is that spring sources are present and they are served, but they are all in one dependency, other dependencies don't have source attachments, however their sources is in the "spring" dependency.

Ah. I see.

I don't think there's much you (or m2eclipse) can do about that. That's arguably a bug in the Spring 2.0.x POM files or in the dependent POM files. Certainly, later versions of Spring (2.5.x and 3.0.x) don't have that problem.


If you are using the current versions of the m2eclipse aka m2e plugin, you don't need to do eclipse:eclipse anymore. Just do everything inside Eclipse. You should be able to just update the dependency in your POM, right-click on your project, and automatically download all attached sources.

0

精彩评论

暂无评论...
验证码 换一张
取 消