I'm doing some testing work that requires the use of features in JUnit which are unfamiliar to me. In order to better understand these features I'd like to be able to view the JUnit sources inside IntelliJ alongside my project.
This project uses Maven. I have the following dependency for jUnit listed in my pom.xml file:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
</dependency>
When I run "mvn clean install" on the command line the jUnit sources are downloaded from my company's Maven repository into my local Maven repository (.m2 directory). The project then compiles and runs without issue.
After right-clicking on the pom.xml file and selecting Maven->Reimport I can see that the classes, sources, and javadocs for jUnit are also present in the library settings in IntelliJ:
However, when I try to open a jUnit class file in IntelliJ and click on the "Download Sources" link I see this:
It seems to might like IntelliJ should be finding these sources just fine locally. Even if it did have to download them from my company's repository I also believe it should find them there since that's where the junit-4.10-sources.jar file in my local repository originally came from.
What might be keeping IntelliJ from loading the sources from the JAR file that it already knows about?
I was able to replicate this in IntelliJ 16 on Windows.
Here is how I resolved it:
pom.xml
file and select Maven -> ReimportI had the same problem. In my case I have 2 projects developed locally (project A and B) where project B is a dependency of the project A. I solved it by:
First: On project B add the following plugin to your pom file:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>verify</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
More info about this plugin here: https://maven.apache.org/plugins/maven-source-plugin/usage.html
Second: On project B root folder run: mvn source:jar
followed by mvn install
.
The first command will generate the sources and the second will publish them in your local repo.
Then IntelliJ, on project A, automatically picked up the sources from project B. If it doesn't then you may need to reload your project dependencies on project A or run mvn clean install
on the root folder
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With