Gradle with IntelliJ IDEA does not recognise Java and Kotlin source and TestNG tests

This is a cross-posting of this question. I am having trouble with Gradle with Kotlin plugin, IntelliJ and TestNG. The following issues happen:

  • Java and Korlin sources are not recognised through they are in the standard location. It says NO-SOURCE.
  • The IDE does not recognise TestNG and code completion does not work thought this is added to the classpath
  • TestNG tests are not run when I execute testClasses or test tasks

I have the following build.gradle:

buildscript {
	ext {
		picocli = '4.3.2'
		janino = '3.1.2'
		questdb = '5.0.1'
		babl = '0.4.1'
		pac4j = '4.0.2'
		eclipse_collections = '10.2.0'
		logback = '1.2.3'
		junit = '4.12'
		testng = '7.1.0'
		kotlin_version = '1.3.72'
	}

	repositories {
		mavenLocal()
		mavenCentral()
		google()
		jcenter()
	}

	dependencies {
	}
}

plugins {
    id 'java'
	id 'org.jetbrains.kotlin.multiplatform' version "$kotlin_version"
}

apply from: 'activej.gradle'
apply from: 'pac4j.gradle'
apply from: 'kotlin.gradle'

description '...'

java {
	sourceCompatibility = JavaVersion.VERSION_11
	targetCompatibility = JavaVersion.VERSION_11
}

kotlin {
	jvm {
		withJava()
	}
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
	sourceCompatibility = JavaVersion.VERSION_11
	targetCompatibility = JavaVersion.VERSION_11

	kotlinOptions {
		jvmTarget = '11'
		apiVersion = '1.3'
		languageVersion = '1.3'
	}
}

test {
	// enable TestNG support (default is JUnit)
	useTestNG()

	// show standard out and standard error of the test JVM(s) on the console
	testLogging.showStandardStreams = true

	// Fail the 'test' task on the first test failure
	failFast = false

	//we want display the following test events
	testLogging {
		events "PASSED", "FAILED", "SKIPPED"
	}
}

dependencies {
    implementation group: 'info.picocli', name: 'picocli', version: "$picocli"

	implementation group: 'org.codehaus.janino', name: 'janino', version: "$janino"

	implementation group: 'org.questdb', name: 'core', version: "$questdb"

	implementation group: 'com.aitusoftware', name: 'babl', version: "$babl", ext: 'pom'

	implementation group: 'org.eclipse.collections', name: 'eclipse-collections-api', version: "$eclipse_collections"
	implementation group: 'org.eclipse.collections', name: 'eclipse-collections', version: "$eclipse_collections"

	implementation group: 'ch.qos.logback', name: 'logback-classic', version: "$logback"

    // testImplementation group: 'junit', name: 'junit', version: "$junit"

	testImplementation group: 'org.testng', name: 'testng', version: "$testng"
}

Files activej.gradle, pac4j.gradle and `kotlin.gradle has just other depedecies.

My directory structure is:

src
 |- main
      |- java
      |- kotlin
      |- resources
 |- test
      |- java
      |- kotlin
      |- resources

I am using TestNG.

I have a mock test file for the time being:

package com.sirinath.activej.config

import org.testng.annotations.*;

@Test
class TestRouteBuilder {
    @Test
    public fun test() {
        System.out.println("Testing")
    }
}

When I execute testClasses I get:

11:08:29 pm: Executing task 'testClasses'...


> Configure project :server
Kotlin Multiplatform Projects are an experimental feature.

> Task :wrapper

BUILD SUCCESSFUL in 1s
1 actionable task: 1 executed

> Configure project :server
Kotlin Multiplatform Projects are an experimental feature.

> Task :server:compileKotlinJvm NO-SOURCE
> Task :server:compileJava NO-SOURCE
> Task :server:jvmProcessResources NO-SOURCE
> Task :server:processResources SKIPPED
> Task :server:classes UP-TO-DATE
> Task :server:jvmMainClasses UP-TO-DATE
> Task :server:compileTestKotlinJvm NO-SOURCE
> Task :server:compileTestJava NO-SOURCE
> Task :server:jvmTestProcessResources NO-SOURCE
> Task :server:processTestResources SKIPPED
> Task :server:testClasses UP-TO-DATE

BUILD SUCCESSFUL in 947ms
11:08:32 pm: Task execution finished 'testClasses'.

  1. Changing id 'org.jetbrains.kotlin.multiplatform' version "$kotlin_version" to id 'org.jetbrains.kotlin.jvm' version "$kotlin_version" and
  2. removing
kotlin {
    jvm {
        withJava()
    }
}

solves all 3 problems.