2

I install my artifact inside the local repository with the command:

mvn install:install-file -DgroupId=com.rules 
-DartifactId=rulesID -Dversion=0.1 -Dpackaging=jar -Dfile=rules.jar

then i resolve the artifact into my java code using:

org.drools.compiler.kproject.ReleaseIdImpl releaseId = 
new ReleaseIdImpl("com.rules", "rulesID", "LATEST");

And every thing works pretty well.

The day after, it seems that the repository expires, and I need another "mvn install" to get things to work again. The exception I get is this:

Caused by: org.eclipse.aether.resolution.VersionResolutionException: 
Failed to resolve version for com.rules:rulesID:pom:LATEST: Could not find metadata com.rules:rulesID/maven-metadata.xml 
in local (C:\Users\gpiazzolla\.m2\repository)
 at org.apache.maven.repository.internal.DefaultVersionResolver.resolveVersion(DefaultVersionResolver.java:312)

In fact, the maven-metadata.xml inside that directory seems to disappear.


The content of "maven-metadata-local.xml" after reinstall is:

<?xml version="1.0" encoding="UTF-8"?>
<metadata>
  <groupId>com.rules</groupId>
  <artifactId>rulesID</artifactId>
  <versioning>
    <release>0.1</release>
    <versions>
      <version>0.1</version>
    </versions>
    <lastUpdated>20150604080940</lastUpdated>
  </versioning>
</metadata>
Gaetano Piazzolla
  • 1,388
  • 1
  • 16
  • 31

2 Answers2

1

You are going about this the wrong way. In general, it is not a best practice to design software which depends on a non-specific version of an artifact. Also, the "LATEST" field is only intended for plugin resolution. And note that the way LATEST works, may not always guarantee the latest version to be used.

Internally, Maven 2.x used the special version markers RELEASE and LATEST to support automatic plugin version resolution. These metaversions were also recognized in the element for a declaration. For the sake of reproducible builds, Maven 3.x no longer supports usage of these metaversions in the POM. As a result, users will need to replace occurrences of these metaversions with a concrete version. from Maven 3.x Compatibility Notes

If you need the highest version of a released non-plugin artifact you should be using version ranges, see section 3.4.3 here or this answer for an example.

Community
  • 1
  • 1
Laurentiu L.
  • 6,566
  • 1
  • 34
  • 60
  • what if i want to retrieve what is the current release of the repository ? – Gaetano Piazzolla Jun 04 '15 at 12:35
  • The whole point was you shouldn't do it dynamically. You will always know the version and you insert it manually. Relying on automatic changes may result in various disasters. That's why they removed the metaversions. – Laurentiu L. Jun 04 '15 at 12:36
  • but using the version range is somehow dynamic – Gaetano Piazzolla Jun 04 '15 at 12:37
  • Oh yes. I thought you meant an abstract latest version. The intervals can be a bit more constrictive which can work. It's a case by case basis regarding which actual interval to use. You may know the convention you set from one minor version to another and major and so on. – Laurentiu L. Jun 04 '15 at 12:37
  • and i cant do anything like this with the current release ( not the latest ) – Gaetano Piazzolla Jun 04 '15 at 12:39
  • What do you mean you can't do anything like this with the current release(not the latest)? You could use an interval such as [0.1,1.0) and set the convention that up to 1.0 you won't break any method signatures and so on. – Laurentiu L. Jun 04 '15 at 12:41
  • http://stackoverflow.com/questions/30571/how-do-i-tell-maven-to-use-the-latest-version-of-a-dependency/1172371#1172371 the last version of a maven artifact is not the release. Using E.g. [0.1) i can select the Latest release anyway, but there is no way to select automatically the current release? – Gaetano Piazzolla Jun 04 '15 at 13:15
  • Yes, that is an example i linked in the answer. What about it? – Laurentiu L. Jun 04 '15 at 13:16
1

Finally I've managed this. There is a bug when is used the Drools implementation to find the artifact and the maven repository is local and not remote.

Check this out: DROOLS-465

Gaetano Piazzolla
  • 1,388
  • 1
  • 16
  • 31