1

I've discovered the wonderful test-jar facility in Maven: https://maven.apache.org/plugins/maven-jar-plugin/examples/create-test-jar.html

But it may so happen that one project needs to use the test-jar of another project. From https://stackoverflow.com/a/6469256/421049 and experimentation, it would seem that using mvn install does not install the test-jar to the local ~/.m2/repository. So how does one project on my machine use the test jars of another project not in the same aggregate POM?

Yet it would seem from Maven deploy not to upload test jar that deployment of a project to Maven Central does in fact deploy the test-jar? So I can deploy it to Nexus but not install it locally? And if I deploy it to Nexus, will my local project using a dependency of <type>test-jar</type> go find it on Maven Central?

Garret Wilson
  • 18,219
  • 30
  • 144
  • 272
  • I'm not sure what brings you to the conclusion that the test-jar is not installed nor uploaded to a remote repository ? Apart from that the description of the link for `Maven deploy not to upload test jar` was intended to prevent uploading the test-jar to a remote repository...based on the size of the resulting jar...something different... – khmarbaise Oct 26 '17 at 15:23
  • 1
    For more help, post your `pom.xml` first. – carlspring Oct 26 '17 at 17:31
  • "I'm not sure what brings you to the conclusion that the test-jar is not installed..." I opened up my `~/.m2/repository` directory tree and I saw no test jars. But I just checked again and they are there, so I may have been looking in the wrong directory the first time. (I have several similarly-named projects.) – Garret Wilson Oct 26 '17 at 21:54
  • "...nor uploaded to a remote repository?" Actually my question indicates that I understood that it _does_ upload to a remote repository, hence my confusion at the apparent discrepancy. – Garret Wilson Oct 26 '17 at 21:58
  • You mean the discrepancy between the different post ? – khmarbaise Oct 27 '17 at 10:48
  • No, I was confused between the apparent discrepancy of Maven not _installing_ a test-jar, but still _deploying_ it to Nexus. As I note in another comment, this may have been my mistake; if Maven does in fact install a test-jar to the local repository, and Maven also deploys a test-jar to Nexus, there is no discrepancy. – Garret Wilson Oct 27 '17 at 14:30
  • OK, now I'm more confused than ever. Somehow I had the test-jar in my local Maven repository. But my colleague was running into build problems, so I removed the test-jar from my local repository. Now my Maven project won't build anymore, and even running `mvn install` for the project won't store the test-jar in my local repository. I'll investigate further... – Garret Wilson Oct 27 '17 at 23:07
  • Hahaha! I found the source of the problem, which explains everything. See my separate answer. – Garret Wilson Oct 27 '17 at 23:52
  • And yes, @carlspring, you're right: if I would have posted the entire `pom.xml` it would have helped. :) – Garret Wilson Oct 28 '17 at 00:00

2 Answers2

3

In my case, I was setting maven.test.skip for a particular build profile. That property actually causes tests to not be compiled/installed, thus also preventing their deploy. The solution was to set the skipTests property instead.

Matthew Read
  • 1,365
  • 1
  • 30
  • 50
1

It turns out that maven-jar-plugin does in fact install the test-jar (e.g. foo-1.2.3-tests.jar) in the local Maven repository ~/.m2/repository/.... Wonderful!

My problem is that I had inadvertently configured the maven-jar-plugin to be in a separate profile named release. (I had copied and pasted to the wrong location in my POM.) That's why the test-jar didn't show up in my local repository after a mvn install, and that's why it suddenly showed up later (after I used -P release once in testing), and I thought I had just missed it when I looked the first time.

I move the maven-jar-plugin to the <build> section and everything is working fine: the test-jar gets put into the local maven repository using mvn install.

Garret Wilson
  • 18,219
  • 30
  • 144
  • 272