Gradle import error in IntelliJ - intellij-idea

I've been used to Maven and now I'm trying to import a Gradle based project in IntelliJ:
apply plugin: 'idea'
subprojects {
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'eclipse'
repositories {
mavenCentral()
}
dependencies {
compile 'javax.ws.rs:jsr311-api:1.1.1'
compile 'com.google.guava:guava:r09'
compile 'com.sun.jersey:jersey-server:1.17.1'
compile 'com.sun.jersey:jersey-core:1.17.1'
compile 'com.sun.jersey:jersey-servlet:1.17.1'
compile 'com.sun.jersey:jersey-json:1.17.1'
compile 'com.fasterxml.jackson.core:jackson-core:2.2.1'
compile 'com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:2.2.1'
compile 'com.fasterxml.jackson.core:jackson-databind:2.2.1'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.2.1'
compile 'commons-io:commons-io:2.4'
testCompile 'junit:junit:4.11'
}
group = 'com.kinvey'
version = '0.1.0'
// Checkstyle
apply plugin: 'checkstyle'
checkstyle {
ignoreFailures = true
configFile = rootProject.file('codequality/checkstyle.xml')
}
// FindBugs
apply plugin: 'findbugs'
findbugs {
ignoreFailures = true
}
// PMD
apply plugin: 'pmd'
//tasks.withType(Pmd) { reports.html.enabled true }
// apply plugin: 'cobertura'
// cobertura {
// sourceDirs = sourceSets.main.java.srcDirs
// format = 'html'
// includes = ['**/*.java', '**/*.groovy']
// excludes = []
// }
}
Here's how I import it and the error:
What can be wrong in the way I import the project?

Related

IntelliJ IDEA does not find candidates for kotlinOptions property but project works fine

I always create Kotlin projects with Gradle: File -> New -> Project -> Gradle -> Kotlin/JVM.
The project works fine, however, IntelliJ IDEA highlights this part of the code:
build.gradle false warning
Is there a way to remove this warning?
This is the entire build.gradle file:
plugins {
id "java"
id "org.jetbrains.kotlin.jvm" version "$kotlinVersion"
}
group "com.alelad"
version "1.0-SNAPSHOT"
allprojects {
apply plugin: "java"
apply plugin: "org.jetbrains.kotlin.jvm"
repositories {
mavenCentral()
jcenter()
}
dependencies {}
compileKotlin {
kotlinOptions {
jvmTarget = "13"
allWarningsAsErrors = true
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = "13"
allWarningsAsErrors = true
}
}
}
Just remove compileKotlin and compileTestKotlin all together. They are deprecated now and your project should work just fine without them. That's what I'm doing and everything works great in all my projects.

How to add coverage report (JaCoCo) to kotest based using build.gradle.kts?

I use Kotlin for server side, and I want to add test coverage (by using JaCoCo but can be any other open source).
At the moment, I don't find any documentation to explain how to enable/add coverage report to kotlin project based on kotest which actually works.
(Yes I tried the official documentation)
build.gradle.kts:
import Libraries.coroutines
import Libraries.koTest
import Libraries.koTestCore
import Libraries.mockk
import Libraries.testcontainers
import Libraries.testcontainersPostgres
plugins {
java
`kotlin-dsl` version "1.3.5" apply false
kotlin("jvm") version Versions.kotlin_version
kotlin("plugin.serialization") version Versions.kotlin_version apply false
id("com.diffplug.gradle.spotless") version Plugins.spotless
id("com.palantir.docker") version Plugins.docker apply false
id("com.palantir.docker-run") version Plugins.docker apply false
id("com.google.protobuf") version Plugins.protobuf apply false
id("org.flywaydb.flyway") version Plugins.flyway apply false
}
allprojects {
group = "my-app"
version = "2.0"
apply(plugin = "kotlin")
apply(plugin = "com.diffplug.gradle.spotless")
repositories {
mavenCentral()
jcenter()
}
tasks {
compileKotlin {
dependsOn(spotlessApply)
kotlinOptions {
jvmTarget = "11"
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = "11"
}
}
}
java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
tasks.withType<Test> {
useJUnitPlatform()
maxParallelForks = 1
environment("ENV", "test")
}
afterEvaluate {
project.configurations.forEach {
// Workaround the Gradle bug resolving multiplatform dependencies.
if (it.name.contains("Proto")) {
it.attributes.attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage::class.java, Usage.JAVA_RUNTIME))
}
}
}
}
subprojects {
spotless {
kotlin {
ktlint().userData(mapOf("disabled_rules" to "no-wildcard-imports"))
trimTrailingWhitespace()
endWithNewline()
}
}
dependencies {
implementation(coroutines)
testImplementation(koTest)
testImplementation(koTestCore)
testImplementation(mockk)
testImplementation(testcontainers)
testImplementation(testcontainersPostgres)
}
configurations {
all {
resolutionStrategy.setForcedModules("org.apache.httpcomponents:httpclient:4.5.9")
}
}
}
Any help will be great. Thanks in advance.
in my experience, Jacoco and Kotest interoperate just fine out of the box. I'm using it and all I need to do is the following:
plugins {
jacoco
// The rest of your plugins
}
// Your build, as it was before
You can inspect a working Jacoco + Kotest build here.
To verify that it works, you can e.g., feed the Jacoco generated data to services such as Codecov.io.
First, generate the report in XML format:
tasks.jacocoTestReport {
reports {
xml.isEnabled = true
}
}
And then use the Codecov.io service to fetch and analyze the results:
bash <(curl -s https://codecov.io/bash)
As you can see in this report, Jacoco is doing its job without further configuration.

gradle build not generating jacoco test report

In my gradle build script, I have a section which says to generate a test report when I run task : jacocoTestReport
jacocoTestReport {
group = "build"
reports {
xml.enabled false
csv.enabled false
html.destination "${buildDir}/reports/coverage"
}
}
When I run the task, it gives me an error :
Unable to read execution data file ..\build\jacoco\test.exec
How can I fix this error. When I do gradle build on the complete project, I see test report is getting generated.
You may need to import jacoco plugin
apply plugin: "jacoco"
My gradle.build as follows and working fine
apply plugin: "java"
apply plugin: "eclipse"
apply plugin: "idea"
apply plugin: "jacoco"
repositories {
mavenCentral()
}
dependencies {
testCompile "junit:junit:4.12"
}
test {
testLogging {
exceptionFormat = 'full'
events = ["passed", "failed", "skipped"]
}
finalizedBy jacocoTestReport
}
jacocoTestReport{
group = "build"
reports {
xml.enabled false
csv.enabled false
html.destination file("${buildDir}/jacocoHtml")
}
}

Warning with maven repository in build.gradle in IntelliJ

I am trying to setup a new scala project in IntelliJ (2016.3.4, built on January 31, 2017) with gradle. My build.gradle is as given below:
group 'org.microservices.architecture'
version '1.0-SNAPSHOT'
apply plugin: 'scala'
repositories {
mavenCentral()
}
dependencies {
compile 'org.scala-lang:scala-library:2.10.1'
}
tasks.withType(ScalaCompile) {
ScalaCompileOptions.metaClass.daemonServer = true
ScalaCompileOptions.metaClass.fork = true
ScalaCompileOptions.metaClass.useAnt = false
ScalaCompileOptions.metaClass.useCompileDaemon = false
}
dependencies {
compile group: 'com.typesafe.akka', name: 'akka-actor_2.11', version: '2.4.17'
compile group: 'org.scala-lang', name: 'scala-library', version: '2.12.1'
testCompile 'org.scalatest:scalatest_2.11:3.0.1'
testCompile 'junit:junit:4.12'
}
sourceSets {
main {
scala {
srcDirs = ['src/scala']
}
}
test {
scala {
srcDirs = ['test/scala']
}
}
}
The problem is I get following warning message:
The following repositories used in your gradle projects were not indexed yet: https://repo1.maven.org/maven2.
If you want to use dependency completion for these repositories
artifacts, Open Repositories List, select required repositories and
press "Update" button.

Gradle + Robolectric + Espresso: can't run separately

I tried to adapt following template: deckard-gradle
I use Android Studio 0.8.14 (beta).
This is my build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'robolectric'
android {
compileSdkVersion 21
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.example.myapp"
minSdkVersion 18
targetSdkVersion 21
versionCode 1
versionName "1.0"
testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
androidTest {
setRoot('src/test')
}
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
}
robolectric {
include '**/*Test.class'
exclude '**/espresso/**/*.class'
}
configurations {
apt
}
apt {
arguments {
resourcePackageName android.defaultConfig.packageName
androidManifestFile variant.outputs[0].processResources.manifestFile
}
}
ext {
daggerVersion = '1.2.2';
androidAnnotationsVersion = '3.2';
robobindingVersion = '0.8.9';
jodatimeVersion = '2.5.1';
ormliteVersion = '4.48';
ottoVersion = '1.3.5';
commonsioVersion = '2.0.1';
playservicesVersion = '6.1.71';
supportv4Version = '21.0.2';
javaxinjectVersion = '1';
junitVersion = '4.11';
robolectricVersion = '2.4';
}
dependencies {
// Espresso
androidTestCompile files('libs/espresso-1.1.jar', 'libs/testrunner-1.1.jar', 'libs/testrunner-runtime-1.1.jar')
androidTestCompile 'com.google.guava:guava:14.0.1'
androidTestCompile 'com.squareup.dagger:dagger:1.2.2'
androidTestCompile 'org.hamcrest:hamcrest-integration:1.1'
androidTestCompile 'org.hamcrest:hamcrest-core:1.1'
androidTestCompile 'org.hamcrest:hamcrest-library:1.1'
androidTestCompile("junit:junit:${junitVersion}") {
exclude module: 'hamcrest-core'
}
androidTestCompile("org.robolectric:robolectric:${robolectricVersion}") {
exclude module: 'classworlds'
exclude module: 'commons-logging'
exclude module: 'httpclient'
exclude module: 'maven-artifact'
exclude module: 'maven-artifact-manager'
exclude module: 'maven-error-diagnostics'
exclude module: 'maven-model'
exclude module: 'maven-project'
exclude module: 'maven-settings'
exclude module: 'plexus-container-default'
exclude module: 'plexus-interpolation'
exclude module: 'plexus-utils'
exclude module: 'wagon-file'
exclude module: 'wagon-http-lightweight'
exclude module: 'wagon-provider-api'
}
androidTestCompile 'com.squareup:fest-android:1.0.+'
apt "org.robobinding:codegen:$robobindingVersion"
compile("org.robobinding:robobinding:$robobindingVersion:with-dependencies") {
exclude group: 'com.google.guava', module: 'guava'
}
apt "org.androidannotations:androidannotations:${androidAnnotationsVersion}"
compile "org.androidannotations:androidannotations-api:${androidAnnotationsVersion}"
apt "com.squareup.dagger:dagger-compiler:${daggerVersion}"
compile "com.squareup.dagger:dagger:${daggerVersion}"
compile fileTree(dir: 'libs', include: ['*.jar'])
compile "com.google.android.gms:play-services:${playservicesVersion}"
compile "com.android.support:support-v4:${supportv4Version}"
compile "com.squareup:otto:${ottoVersion}"
compile "javax.inject:javax.inject:${javaxinjectVersion}"
compile "com.j256.ormlite:ormlite-core:${ormliteVersion}"
compile "com.j256.ormlite:ormlite-android:${ormliteVersion}"
compile group: 'commons-io', name: 'commons-io', version: "${commonsioVersion}"
compile "net.danlew:android.joda:${jodatimeVersion}"
}
apply plugin: 'idea'
idea {
module {
testOutputDir = file('build/test-classes/debug')
}
}
android.applicationVariants.all { variant ->
def aptOutput = file("${project.buildDir}/generated/source/apt/${variant.dirName}")
println "****************************"
println "variant: ${variant.name}"
println "manifest: ${variant.processResources.manifestFile}"
println "aptOutput: ${aptOutput}"
println "****************************"
variant.javaCompile.doFirst {
println "*** compile doFirst ${variant.name}"
aptOutput.mkdirs()
variant.javaCompile.options.compilerArgs += [
'-processorpath', configurations.apt.getAsPath(),
'-AandroidManifestFile=' + variant.processResources.manifestFile,
'-s', aptOutput
]
}
}
I tried to ways to run unit tests:
When I use gradlew test I get exceptions because all tests (also instrumentation) are executed.
When I use Android Studio to run a JUnit test I get this error:
!!! JUnit version 3.8 or later expected:
java.lang.RuntimeException: Stub!
at junit.runner.BaseTestRunner.<init>(BaseTestRunner.java:5)
at junit.textui.TestRunner.<init>(TestRunner.java:54)
at junit.textui.TestRunner.<init>(TestRunner.java:48)
at junit.textui.TestRunner.<init>(TestRunner.java:41)
at com.intellij.rt.execution.junit.JUnitStarter.junitVersionChecks(JUnitStarter.java:190)
at com.intellij.rt.execution.junit.JUnitStarter.canWorkWithJUnitVersion(JUnitStarter.java:173)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:56)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Process finished with exit code -3
For various reasons, I've abandoned the above approach in favor of keeping my Robolectric tests in a Gradle submodule. You can find a blog post I wrote about why I moved in this direction and a fork of the deckard-gradle project that shows you how here.