2

When im using the following dependencies in my pom file:

<properties>
    <rxkotlinfx.version>2.2.0</rxkotlinfx.version>
    <rxkotlin.version>2.1.0</rxkotlin.version>
    <kotlin.version>1.1.51</kotlin.version>
    <tornadofx.version>1.7.12</tornadofx.version>
</properties>

<dependencies>
    <dependency>
        <groupId>com.github.thomasnield</groupId>
        <artifactId>rxkotlinfx</artifactId>
        <version>${rxkotlinfx.version}</version>
    </dependency>
    <dependency>
        <groupId>io.reactivex.rxjava2</groupId>
        <artifactId>rxkotlin</artifactId>
        <version>${rxkotlin.version}</version>
    </dependency>
    <dependency>
        <groupId>no.tornado</groupId>
        <artifactId>tornadofx</artifactId>
        <version>${tornadofx.version}</version>
    </dependency>
    <dependency>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-stdlib</artifactId>
        <version>${kotlin.version}</version>
    </dependency>
    <dependency>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-test</artifactId>
        <version>${kotlin.version}</version>
        <scope>test</scope>
    </dependency>
</dependencies>

And running the following code:

fun main(args: Array<String>) {
    val source = listOf("A", "B", "C").toObservable()
            .filter { it == "B" }
            .subscribeBy(
                    onNext = { println(it) }
            )
}

Im getting the following error:

Error:(37, 40) Kotlin: Cannot access class 'io.reactivex.Observable'. Check your module classpath for missing or conflicting dependencies

Why am I getting this error and what setup of dependencies do I need to be able to work with this stack?

user3139545
  • 6,882
  • 13
  • 44
  • 87
  • What happens if you run `mvn dependency:tree` ? If it shows up twice with different versions, it is a good idea to add an explicit dependency on it in your `pom.xml` – Simon Forsberg Nov 10 '17 at 08:37

2 Answers2

2

The only solution I found was to make an explicit dependency on:

<dependency>
    <groupId>io.reactivex.rxjava2</groupId>
    <artifactId>rxjava</artifactId>
    <version>2.1.3</version>
</dependency>
user3139545
  • 6,882
  • 13
  • 44
  • 87
0

io.reactivex.Observable resides in rxjava-2.1.3.jar library, which is a transitive dependency brought by 2 dependencies you declared in pom.xml:

  • com.github.thomasnield:rxkotlinfx:2.2.0

  • io.reactivex.rxjava2:rxkotlin:2.1.0

I tried your setup with gradle (sorry, I like more gradle than maven) and I use gradle command line to see what is the conflict resolution: Here is the outcome:

io.reactivex.rxjava2:rxjava:2.1.3 (conflict resolution)
\--- io.reactivex.rxjava2:rxjavafx:2.2.0
     \--- com.github.thomasnield:rxkotlinfx:2.2.0
          \--- compileClasspath

io.reactivex.rxjava2:rxjava:2.1.0 -> 2.1.3
\--- io.reactivex.rxjava2:rxkotlin:2.1.0
     \--- compileClasspath

io.reactivex.rxjava2:rxjavafx:2.2.0
\--- com.github.thomasnield:rxkotlinfx:2.2.0
     \--- compileClasspath

io.reactivex.rxjava2:rxkotlin:2.1.0 (selected by rule)
\--- compileClasspath

and gradle conflict resolution chosen the v 2.1.3

I know that dependency management in gradle is more powerful than in maven, but I would force maven to use a specific version of the transitive dependency by excluding the unwanted dependency version.

I would try the following:

<dependency>
  <groupId>io.reactivex.rxjava2</groupId>
  <artifactId>rxkotlin</artifactId>
  <version>${rxkotlin.version}</version>
  <exclusions>
    <exclusion>
      <groupId>io.reactivex.rxjava2</groupId>
      <artifactId>rxjava</artifactId>
    </exclusion>
  </exclusions>
</dependency>

Or, in case you don't need some API from it, you can remove the

    <dependency>
        <groupId>com.github.thomasnield</groupId>
        <artifactId>rxkotlinfx</artifactId>
        <version>${rxkotlinfx.version}</version>
    </dependency> 
jtonic
  • 609
  • 1
  • 7
  • 10
  • Even after exclusion it does not work, it solves the conflict but im getting the same error. – user3139545 Nov 09 '17 at 09:07
  • I would try the following: 1. mvn dependency:tree -Dverbose -Dincludes= rxjava2 2. mvn compile 3. run the application with exec maven plugin (java) - http://www.mojohaus.org/exec-maven-plugin/usage.html 4. (optional) delete local maven cache 5. check the versions of idea kotlin plugin and maven plugin. I urge you to keep the same value. – jtonic Nov 12 '17 at 08:16