-1

I have a Maven project which holds a number of shared classes for two other projects (one maven Java SE project and one Android project).

I need to package this shared jar up in the other projects when I do a build.

Now I know of Nexus, but I'm working without access to a shared installation of it.

Is the only option to include the shared jar as part of the maven/gradle projects in src/main/resources for example?

PDStat
  • 5,513
  • 10
  • 51
  • 86
  • You could use maven local with your dependencies scope set to system. see it here: https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html – Jorge Campos Oct 08 '15 at 13:05
  • Wasn't me. But I guess that it was because you didn't provide much more details like your project configurations. – Jorge Campos Oct 08 '15 at 13:08
  • Stackoverflow is awesome: http://stackoverflow.com/questions/2229757/maven-add-a-dependency-to-a-jar-by-relative-path – Gimby Oct 08 '15 at 13:13
  • ok thanks, both of these comments kind of backup my assertion with a bit more detail – PDStat Oct 08 '15 at 13:16

1 Answers1

1

The best answer is to host your own internal host repository. See here for more details. We use SonaType Nexus.

However, you could just rely on your "local repo". When you do mvn install, the artifacts you build get hosted to your local filesystem, typically at ~/.m2/repository. See your Maven settings.xml for the exact location.

So, if you always build your shared code first with mvn clean install, the shared artifacts will be available when you do mvn clean install in the projects that use it. Of course, this will mean that the artifacts are not published and remain local to your build server or local machine. This defeats somewhat the dependency management feature of Maven.

sh0rug0ru
  • 1,596
  • 9
  • 9
  • As I said Nexus isn't an option at the moment, and relying on the local filesystem isn't great as it's a shared project. I guess I'll just add the jar as managed resource in the git project as I mentioned – PDStat Oct 08 '15 at 13:17
  • There are other options. See [here](https://maven.apache.org/guides/introduction/introduction-to-repositories.html). Note, as long as the file is accessible by URL, such as `file://` or `http://`, it doesn't really matter how you make the files available. You can use an ordinary web server or remote filesystem mount. – sh0rug0ru Oct 08 '15 at 13:21
  • thanks that's useful, I'll keep it in mind, for the moment I've gone with the system scope dependency, I may revisit this later – PDStat Oct 08 '15 at 13:45