Maven build failed due to JDT dependencies - No versions available for org.osgi.service:org.osgi.service.prefs:jar:[1.1.0,1.2.0)

Viewed 5189

Today when I tried to install my maven project, I get an error due JDT dependencies and here is the report information:

Cannot resolve No versions available for org.osgi.service:org.osgi.service.prefs:jar:[1.1.0,1.2.0) within specified range.
[ERROR] Failed to execute goal on project redundantcheck: 
Could not resolve dependencies for project edu.fudan.selab:redundantcheck:jar:1.0-SNAPSHOT: 
Failed to collect dependencies at org.eclipse.jdt:org.eclipse.jdt.core:jar:3.20.0 -> 
org.eclipse.platform:org.eclipse.core.resources:jar:3.12.0 -> 
org.eclipse.platform:org.eclipse.core.expressions:jar:3.5.100 -> 
org.eclipse.platform:org.eclipse.core.runtime:jar:3.12.0 -> 
org.eclipse.platform:org.eclipse.equinox.preferences:jar:3.10.0 -> 
org.osgi.service:org.osgi.service.prefs:jar:[1.1.0,1.2.0): No versions available for 
org.osgi.service:org.osgi.service.prefs:jar:[1.1.0,1.2.0) within specified range -> [Help 1]

I tried to add 1.1.0 org.osgi.service:org.osgi.service.prefs to the project, but still can't solve this problem. To avoid dependency update, I specied almost every version of the dependencies, but still encounter this error today. Here is my pom.xml:

    <dependencies>
        <dependency>
            <groupId>org.eclipse.jdt</groupId>
            <artifactId>org.eclipse.jdt.core</artifactId>
            <version>3.20.0</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.platform</groupId>
            <artifactId>org.eclipse.core.commands</artifactId>
            <version>3.9.800</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.eclipse.platform/org.eclipse.core.contenttype -->
        <dependency>
            <groupId>org.eclipse.platform</groupId>
            <artifactId>org.eclipse.core.contenttype</artifactId>
            <version>3.7.900</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.eclipse.platform/org.eclipse.core.filesystem -->
        <dependency>
            <groupId>org.eclipse.platform</groupId>
            <artifactId>org.eclipse.core.filesystem</artifactId>
            <version>1.7.700</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.eclipse.platform/org.eclipse.core.jobs -->
        <dependency>
            <groupId>org.eclipse.platform</groupId>
            <artifactId>org.eclipse.core.jobs</artifactId>
            <version>3.10.1100</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.eclipse.platform/org.eclipse.core.resources -->
        <dependency>
            <groupId>org.eclipse.platform</groupId>
            <artifactId>org.eclipse.core.resources</artifactId>
            <version>3.14.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.eclipse.platform/org.eclipse.core.runtime -->
        <dependency>
            <groupId>org.eclipse.platform</groupId>
            <artifactId>org.eclipse.core.runtime</artifactId>
            <version>3.20.100</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.eclipse.platform/org.eclipse.equinox.common -->
        <dependency>
            <groupId>org.eclipse.platform</groupId>
            <artifactId>org.eclipse.equinox.common</artifactId>
            <version>3.14.100</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.eclipse.platform/org.eclipse.osgi -->
        <dependency>
            <groupId>org.eclipse.platform</groupId>
            <artifactId>org.eclipse.osgi</artifactId>
            <version>3.16.200</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.eclipse.platform/org.eclipse.text -->
        <dependency>
            <groupId>org.eclipse.platform</groupId>
            <artifactId>org.eclipse.text</artifactId>
            <version>3.11.0</version>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.6.1</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.75</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.platform</groupId>
            <artifactId>org.eclipse.core.expressions</artifactId>
            <version>3.8.0</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.platform</groupId>
            <artifactId>org.eclipse.equinox.app</artifactId>
            <version>1.6.0</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.platform</groupId>
            <artifactId>org.eclipse.equinox.preferences</artifactId>
            <version>3.9.0</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.platform</groupId>
            <artifactId>org.eclipse.equinox.registry</artifactId>
            <version>3.11.0</version>
        </dependency>
    </dependencies>

Is there anyway to solve this problem?

7 Answers

EDIT: The issue is known by the project team and tracked as eclipse-equinox/equinox.bundles#54 on GitHub.

The dependency:

<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.equinox.preferences</artifactId>
<version>3.10.0</version>

Which is one of your transitive dependency, references this dependency in its dependencies list:

<dependency>
    <groupId>org.osgi.service</groupId>
    <artifactId>org.osgi.service.prefs</artifactId>
    <version>[1.1.0,1.2.0)</version>
</dependency>

Source: org.eclipse.equinox.preferences-3.10.0.pom on maven central.

It is a mistake. As Maven tells you, this does not exist:

Cannot resolve No versions available for org.osgi.service:org.osgi.service.prefs:jar:[1.1.0,1.2.0) within specified range.

It should have been:

<dependency>
    <groupId>org.osgi</groupId>
    <artifactId>org.osgi.service.prefs</artifactId>
    <version>[1.1.0,1.2.0)</version>
</dependency>

Which exists (note the different groupId).

Because you are not fixing the dependencies you are consuming in your project, and because the dependencies are using version ranges, suddenly you got a new version.

By the way as beingnurd has noted, there is now the newer version 3.10.1 of org.eclipse.equinox.preferences where this wrong dependency is fixed (see org.eclipse.equinox.preferences-3.10.1.pom).

If you continue to use always the newest dependency of the compatible range, the problem will be solved for you.


Now if we take a step back:

You are trying to use following JDT version:

<dependency>
    <groupId>org.eclipse.jdt</groupId>
    <artifactId>org.eclipse.jdt.core</artifactId>
    <version>3.20.0</version>
</dependency>

This corresponds to the Eclipse Version 2019-12 (also called 4.14 internally).


Your problem is that the eclipse projects (org.eclipse.jdt.core and all the dependencies) are using version ranges. If you look at the org.eclipse.jdt.core dependencies declarations:

  • org.eclipse.platform:org.eclipse.core.resources:[3.12.0,4.0.0)
  • org.eclipse.platform:org.eclipse.core.runtime:[3.13.0,4.0.0)
  • org.eclipse.platform:org.eclipse.core.filesystem:[1.7.0,2.0.0)
  • org.eclipse.platform:org.eclipse.text:[3.6.0,4.0.0)

If you don't do anything, Maven always takes the latest:

Today (June 2022) this would be:

  • org.eclipse.core.resources: 3.16.100
  • org.eclipse.core.runtime: 3.24.100
  • org.eclipse.core.filesystem: 1.9.300
  • org.eclipse.text: 3.12.0

When the library was published (December 2019) this was:

  • org.eclipse.core.resources: 3.13.600
  • org.eclipse.core.runtime: 3.17.0
  • org.eclipse.core.filesystem: 1.7.600
  • org.eclipse.text: 3.10.0

And of course this is recursive, you need to do this for all the dependencies.


Letting Maven choose always the latest is problematic:

  • It prevents you creating reproducible build, because the dependencies picked by maven depends from what is available on maven central on that day.
  • You need to solve conflicts.
  • You are potentially the first trying out a combination.

This is why I always use a set of projects that were released together. By the way this is also how the Eclipse project itself is doing it (by using P2 update sites and target platform).

I am publishing Maven BOM files to fix the versions: ECentral project


This is how you can do it:

  <repositories>
    <repository>
      <id>ecentral</id>
      <url>https://raw.githubusercontent.com/jmini/ecentral/HEAD/repo</url>
    </repository>
  </repositories>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>fr.jmini.ecentral</groupId>
        <artifactId>eclipse-platform-dependencies</artifactId>
        <version>4.14</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <dependencies>
    <dependency>
      <groupId>org.eclipse.jdt</groupId>
      <artifactId>org.eclipse.jdt.core</artifactId>
      <!-- no version needed here, because it is defined in the BOM -->
    </dependency>
  </dependencies>

Because I ran into this problem today too, but via plugin sub-dependency, my temporary solution is to download the regular org.osgi:org.osgi.service.prefs:jar:1.1.2 and install it in the local repository as org.osgi.service:org.osgi.service.prefs:jar:1.1.2.

You can exclude the dependency like this :

<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.core</artifactId>
<version>3.24.0</version>
<exclusions>
    <exclusion>
        <groupId>org.osgi.service</groupId>
        <artifactId>org.osgi.service.prefs</artifactId>
    </exclusion>
</exclusions>

so the reason for this failure is dependency <groupId>org.osgi.service</groupId> <artifactId>org.osgi.service.prefs</artifactId>

but the group org.osgi.service doesn't exists, instead it is only org.osgi so dependency should look

<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.prefs</artifactId>

I have got the same problem today in our SpringBoot project 1.5.25 with org.hibernate:hibernate-tools:jar:5.0.6.Final

The error message as follow:

# Failed to collect dependencies at org.hibernate:hibernate-tools:jar:5.0.6.Final -> 
# org.eclipse.jdt:org.eclipse.jdt.core:jar:3.12.2 ->
# org.eclipse.platform:org.eclipse.core.resources:jar:3.11.1 ->
# org.eclipse.platform:org.eclipse.core.expressions:jar:3.5.100 ->
# org.eclipse.platform:org.eclipse.core.runtime:jar:3.12.0 -> 
# org.eclipse.platform:org.eclipse.equinox.preferences:jar:3.10.0 -> 
# org.osgi.service:org.osgi.service.prefs:jar:[1.1.0,1.2.0): No versions available for org.osgi.service:org.osgi.service.prefs:jar:[1.1.0,1.2.0) within specified range -> [Help 1]

I use the private nexus, to resolve this problem, i added a proxy maven2 (maven-ecentral) repo pointed to https://raw.githubusercontent.com/jmini/ecentral/HEAD/repo , thanks @Jmini

then added the follow lignes in the pom.xml

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>fr.jmini.ecentral</groupId>
                <artifactId>eclipse-platform-dependencies</artifactId>
                <version>4.14</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <repositories>
        <repository>
            <id>ecentral</id>
            <url>https://nexus.xxxx.xxx/repository/maven-ecentral/</url>
        </repository>
    </repositories>

Reload your project with IDEA, it should work.


Another solution is using exclusions

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-tools</artifactId>
    <version>${hibernate-tools.version}</version>
    <!-- exclure the old org.eclipse.platform -->
   <exclusions>
        <exclusion>
            <groupId>org.eclipse.platform</groupId>
            <artifactId>org.eclipse.equinox.preferences</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<!-- the 3.10.1 org.eclipse.platform fixed the pb -->
<dependency>
    <groupId>org.eclipse.platform</groupId>
    <artifactId>org.eclipse.equinox.preferences</artifactId>
    <version>3.10.1</version>
</dependency>

Even I have been facing this problem since today, it was working fine till yesterday. Finally what I found was that pom of org.eclipse.equinox.preferences:3.10.0 group id mentioned as org.osgi.service, but the artifact is located in repo1.maven.org at org/osgi, there is no service folder in it. I changed dependency group id to org.osgi in the pom of org.eclipse.equinox.preferences and then it worked.

--EDIT-- I can see a new version of 3.10.1 added in repo which has the group id corrected to org.osgi instead of org.osgi.service

I ran into this problem with a maven plugin (net.revelc.code.formatter). We use it from another maven plugin that generates code. Since it is just a formatter for generated code, my solution was to drop the usage of the formatter plugin. Obviously I couldn't use the above solutions, because I don't want to fork the formatter code.

Related