简体   繁体   中英

Intellij Idea 15 Gradle project import Junit compile errors

I am having a issue with simple project's junit in Intellij Idea.

Gradle (2.10) can run the junits from command line. Import the project to Intellij Idea 15.0.3, try to run the JUnit in intellij it throws compile errors as if the junit is not on the classpath. Error:(1, 17) java: package org.junit does not exist

checked the project structure the junit lib is there, also tried the other method adivised - create Test in Intellij 'Goto Test > create new Test >' still not much luck.

build.gradle:

allprojects {
    apply plugin: 'idea'
    apply plugin: 'java'

    sourceCompatibility = 1.7
    group 'junit.fail'
    version '1.0'

    repositories {
    mavenCentral()
    }
}

subprojects {
    dependencies {
    testCompile 'junit:junit:4.12'
    }
}

dependencies {
    compile project(':common')
    compile project(':modA')
}

settings.gradle

rootProject.name = 'junit-fail'
include 'common'
include 'modA'

Simple code in module common

junit-fail\\common\\src\\main\\java

public class ClassA {
    public String getA() {
        return "A";
    }
}

junit-fail\\common\\src\\test\\java

import org.junit.Test;
import static org.junit.Assert.*;

public class ClassATest {
    @Test
    public void testGetA() throws Exception {
        ClassA a = new ClassA();
        assertEquals("A", a.getA());
    }
}

modA can have the similar test code.

Able to resolve the issue by moving .gradle from c:\\users\\ to c:\\dev JDK8 was ok but JDK7 never worked - my home dir is network synced. so that may have been an issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM