2016-03-02 46 views
2

我嘗試使用帶有搖籃的IntelliJ 15.我的build.gradle看起來是這樣的:的IntelliJ,休眠/ JPA和搖籃中沒有發現集結任務相關

plugins { 
    id "org.flywaydb.flyway" version "3.2.1" 
} 

apply plugin: 'java' 
apply plugin: 'idea' 
apply plugin: 'application' 

group 'de.my' 
version '1.0-SNAPSHOT' 

mainClassName = "de.my.hibernateTest.HibernateTest" 

repositories { 
    mavenCentral() 
} 

dependencies { 
    testCompile group: 'junit', name: 'junit', version: '4.11' 
    runtime 'org.hibernate:hibernate-core:5.1.0.Final' 
    runtime 'com.h2database:h2:1.4.191' 
} 

flyway { 
    url = 'jdbc:h2:file:./target/foobar' 
    user = 'sa' 
} 

的IntelliJ和gradle這個是syncronized和IntelliJ找到依賴關係。我可以在gradle-tool-window中看到它們。但如果我嘗試與執行任務建造的gradle崩潰:

C:\Users\XXXXX\Development\Java\DemoH2Hibernate\src\main\java\xxx\yy\zzzzz\hibernateTest\Person.java:3: error: package org.hibernate.annotations does not exist 
import org.hibernate.annotations.GenericGenerator; 
           ^
C:\Users\XXXXX\Development\Java\DemoH2Hibernate\src\main\java\xxx\yy\zzzzz\hibernateTest\Person.java:5: error: package javax.persistence does not exist 
import javax.persistence.Entity; 
         ^
C:\Users\XXXXX\Development\Java\DemoH2Hibernate\src\main\java\xxx\yy\zzzzz\hibernateTest\Person.java:6: error: package javax.persistence does not exist 
import javax.persistence.GeneratedValue; 
         ^
C:\Users\XXXXX\Development\Java\DemoH2Hibernate\src\main\java\xxx\yy\zzzzz\hibernateTest\Person.java:7: error: package javax.persistence does not exist 
import javax.persistence.Id; 
         ^
C:\Users\XXXXX\Development\Java\DemoH2Hibernate\src\main\java\xxx\yy\zzzzz\hibernateTest\Person.java:8: error: package javax.persistence does not exist 
import javax.persistence.Table; 
         ^
C:\Users\XXXXX\Development\Java\DemoH2Hibernate\src\main\java\xxx\yy\zzzzz\hibernateTest\Person.java:14: error: cannot find symbol 
@Entity 
^ 
    symbol: class Entity 
C:\Users\XXXXX\Development\Java\DemoH2Hibernate\src\main\java\xxx\yy\zzzzz\hibernateTest\Person.java:15: error: cannot find symbol 
@Table(name = "PERSON") 
^ 
    symbol: class Table 
C:\Users\XXXXX\Development\Java\DemoH2Hibernate\src\main\java\xxx\yy\zzzzz\hibernateTest\Person.java:20: error: cannot find symbol 
    @Id 
    ^
    symbol: class Id 
    location: class Person 
C:\Users\XXXXX\Development\Java\DemoH2Hibernate\src\main\java\xxx\yy\zzzzz\hibernateTest\Person.java:21: error: cannot find symbol 
    @GeneratedValue(generator = "increment") 
    ^
    symbol: class GeneratedValue 
    location: class Person 
C:\Users\XXXXX\Development\Java\DemoH2Hibernate\src\main\java\xxx\yy\zzzzz\hibernateTest\Person.java:22: error: cannot find symbol 
    @GenericGenerator(name="increment", strategy = "increment") 
    ^
    symbol: class GenericGenerator 
    location: class Person 
10 errors 

我的Person類是:

package xxx.yy.zzzzz.hibernateTest; 

import org.hibernate.annotations.GenericGenerator; 

import javax.persistence.Entity; 
import javax.persistence.GeneratedValue; 
import javax.persistence.Id; 
import javax.persistence.Table; 

@Entity 
@Table(name = "PERSON") 
public class Person { 
    private int id; 
    private String name; 

    @Id 
    @GeneratedValue(generator = "increment") 
    @GenericGenerator(name="increment", strategy = "increment") 
    public int getId() { 
     return id; 
    } 

    public void setId(int id) { 
     this.id = id; 
    } 


    public String getName() { 
     return name; 
    } 

    public void setName(String name) { 
     this.name = name; 
    } 
} 

我不知道還有什麼能原因?

回答

1

它必須是compile不是runtime in build.gradle。