Am 22.06.2017 um 13:55 schrieb Markus Koschany:
> Am 22.06.2017 um 13:38 schrieb Emmanuel Bourg:
>> Le 22/06/2017 à 13:16, Markus Koschany a écrit :
>>
>>> Can we force Maven (or any other build tool) to use an already built
>>> artifact instead of searching for the equivalent in a local or remote
>>> repository?
>>
>> I don't know if this could help in your case, but it's possible to use a
>> local jar by adding the <systemPath> element to the dependency in the pom:
>>
>>   <dependency>
>>     <groupId>org.example</groupId>
>>     <artifactId>foo</artifactId>
>>     <version>1.0</version>
>>     <systemPath>lib/foo-1.0.jar</systemPath>
>>   </dependency>
>>
>> It would work only at build time though, such a dependency couldn't be
>> resolved once the pom is installed in /usr/share/maven-repo.
> 
> Thanks. Good idea. I'll experiment with this solution a little.

Ok, it turned out that I had to use the following hack:

<scope>system</scope>
<systemPath>${user.dir}/lib/twelvemonkeys-common-lang-3.3.2.jar</systemPath>

scope system is strictly required if you try to use a local jar file
that is not (yet) available in some repository. In general Maven doesn't
like relative paths and apparently dislikes the concept of "build module
A and then use output of A for module B". The Internet is full of advice
a la "download the jar from a (local) repository, doh".

If you want to avoid hardcoding the absolute path to the jar, you have
to change the build directory, which is by default "target" in the same
location where the module pom.xml resides. In a multi-module Maven
project you have to patch the parent pom like this:

<build>
<directory>${user.dir}/lib</directory>
</build>

The "root" directory is indeed ${user.dir} not {project.basedir} because
in a multi-module project $basedir is just relative to the module pom.

With all this in place I could build the package without having to rely
on prebuilt jar files. Nevertheless, like you said, such a dependency
couldn't be resolved later, so I have to build-depend on
libtwelvemonkeys-java in the future. Great.

Markus

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to