I have a project that includes some Java APIs, some resource files, and some pre-built machine learning models that can be used by the Java APIs. The models are currently in src/main/resources and the classes load them via Class.getResource. The models are used in several unit tests that make sure the APIs work as expected.
This is all basically fine, except that the models are quite large, and some users of the APIs may not need the models at all. (They’d just need the Java classes and the other smaller resource files.) So I’d like to arrange a distribution where users could choose to include the model files or not.
At first I thought that maybe the models should be a separate Maven project of their own, but if I pulled them out, I’m not sure how the dependencies would work. The models project would have to depend on the primary project for the Java APIs, but the primary project would have to depend on the models project for its tests. So that seems circular.
Then I thought that maybe I should be trying to create a separate jar with a classifier so that, e.g. users that need only the APIs would write:
<dependency>
<groupId>foo</groupId>
<artifactId>bar</artifactId>
<version>0.5.0</version>
</dependency>
and users who wanted both the APIs and the models would write:
<dependency>
<groupId>foo</groupId>
<artifactId>bar</artifactId>
<version>0.5.0</version>
</dependency>
<dependency>
<groupId>foo</groupId>
<artifactId>bar</artifactId>
<version>0.5.0</version>
<classifier>models</classifier>
</dependency>
But I’m not sure how to set things up so that when I run mvn package some resources get separated out into a jar with a different classifier. How can I do that?
(Ideally, this would all happen with just the basic mvn package and would not require futzing around with, say, different profiles, since I would always be packaging things the same way.)
Given these points…
I believe the problem is that you are using the deliverable models for unit testing.
I recommend you do the following:
src/main/resourcesof the new module. Your API module would no longer have models insrc/main/resources.src/test/resources. Make them as minimalist as possible to test the API functionality. Re-write your API unit tests to use those instead. As a starting point you could make a copy of the deliverable models and place them here, but I recommend a smaller set of test data that has examples of each kind of thing a model can contain.That leaves you with no module cycles, models separate from API, unit tests for the API, and optionally unit tests for the deliverable models.