'IntellijIDEA 2021.2.2 does not recognize classes imported from jar file to gradle module

Project structure is shown on the image below:

enter image description here

tictactoe-server-infrastructure module has folder called libs that contains two jar files with some library code. In dependencies section of build.gradle file for tictactoe-server-infrastructure module i have next line implementation fileTree(include: ['*.jar'], dir: 'libs') that allows gradle to recognize classes from that jar files and use their classes in tictactoe-server-infrastructure module.

When i want to add tictactoe-server-infrastructure module as a dependency to tictactoe-server-presentation module i put implementation project(':tictactoe-server-infrastructure') line into the dependencies block of build.gradle file for tictactoe-server-presentation module.

When I try to build a project it builds well with no errors whatsoever.

But as soon as I try to use any of classes from that jar files in tictactoe-server-presentation module that meant to be added as dependencies with tictactoe-server-infrastructure module, IDEA cant seem to recognize them and gradle would not build the project anymore.

I have already tried to invalidate caches and restart, reimport gradle project and delete gradle caches. Also i have tried to add two jars as global libraries and add them to tictactoe-server-presentation through project structure menu from IDEA, but i want to do it completely from gradle as i have done it before.

The strange thing is that on another project with an older gradle version i have used compile method instead, and it worked.

tictactoe-server-infrastructure build.gradle

plugins {
    id 'java'
}

group 'com.ttt'
version '0.1.0'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    compileOnly 'org.projectlombok:lombok:1.18.20'
    annotationProcessor 'org.projectlombok:lombok:1.18.20'

    testCompileOnly 'org.projectlombok:lombok:1.18.20'
    testAnnotationProcessor 'org.projectlombok:lombok:1.18.20'

    implementation fileTree(include: ['*.jar'], dir: 'libs')
}
tictactoe-server-presentation build.gradle


plugins {
    id 'java'
}

group 'com.ttt'
version '0.1.0'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    implementation project(':tictactoe-server-infrastructure')

    compileOnly 'org.projectlombok:lombok:1.18.20'
    annotationProcessor 'org.projectlombok:lombok:1.18.20'

    testCompileOnly 'org.projectlombok:lombok:1.18.20'
    testAnnotationProcessor 'org.projectlombok:lombok:1.18.20'
}


Solution 1:[1]

After another hour of already re-reading gradle documentation and some other articles I have found an answer

I have come to the conslusion that I needed classed from that two jar files to be visible in client classpath (meaning tictactoe-server-presentation module).

implementation does not provide transitivity needed to do that, meaning that classes from that jar files will be visible only for tictactoe-server-infrastructure module and NOT for modules that depend on it.

apiElements on the other hand provides transitivity exposing classes to client classpath.

tl;dr

All i ahd to do is to change tictactoe-server-infrastructure build.gradle file: replace implementation fileTree(include: ['*.jar'], dir: 'libs') with apiElements fileTree(dir: 'libs', include: ['*.jar'])

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ?????? ?.