0

Imagine I have two Maven-based projects with Kotlin code, prjA and prjB.

Test class SomeTest in prjA references a class and function defined in prjB:

class SomeTest {
    @Test
    fun prjACanReferencePrjBStuff() {
        val valRes = ValidationResult()
        val correctValRes = createCorrectValidationResult()
    }
}

When I

  1. run mvn clean install in prjB,
  2. update the dependencies of prjA in IntelliJ Idea and
  3. run mvn clean install in prjA,

I get errors - Maven can't find the classes defined in prjB:

Error in IntelliJ Idea

Why? How can I fix it?

Notes:

  1. Kotlin classes are publicly visible by default. I don't get any errors during mvn install of prjB.
  2. The Maven repository contains prjB artifacts and IntelliJ Idea references the right Maven repository.
  3. When I try to build prjA from the command line, the build succeeds.
  4. Invalidating IntelliJ Idea cache and rebuilding the project doesn't help.

Update 1: I need a solution, which allows me to use prjB not only in tests.

Update 2: Everything works perfectly fine, if I rewrite Kotlin classes in prjB in Java.

1
  • Make a multi module build from it and define the appropriate dependencies between them. Commented Jun 1, 2016 at 9:00

1 Answer 1

1

If you need regular classes from prjB, add main dependency to prjA. If you need test classes from prjB, add test dependency to prjA.

To add main dependency to another module:

<project>
  ...
  <dependencies>
    <dependency>
      <groupId>com.your.group</groupId>
      <artifactId>prjB</artifactId>
      <version>1.0-SNAPSHOT</version>
    </dependency>
  </dependencies>
  ...
</project>

To add test dependency to another module:

<project>
  ...
  <dependencies>
    <dependency>
      <groupId>com.your.group</groupId>
      <artifactId>prjB</artifactId>
      <version>1.0-SNAPSHOT</version>
      <type>test-jar</type>
      <scope>test</scope>
    </dependency>
  </dependencies>
  ...
</project>

Here is an example on test dependency.

Sign up to request clarification or add additional context in comments.

4 Comments

See my update 1. I need to find a way to use prjB not only in tests, but in the normal code as well. Will you proposal work in this case?
See the first code snippet of doge, this will set a 'normal' dependency.
How is the dependency from your first code snippet different from the dependency on prjB in my example ?
@DmitriPisarenko then it's problem in the IDE. Check this

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.