一旦我升级到Hibernate 5.2.3或更高版本,Gradle就再也找不到我的实体类了:
Caused by: java.lang.IllegalArgumentException: Unknown entity: data.model.User
at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:768)
at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:744)
at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:749)
at core.data.model.service.PersistenceService.lambda$create$0(PersistenceService.java:105)
at core.data.model.service.PersistenceService.withTransaction(PersistenceService.java:156)
Run Code Online (Sandbox Code Playgroud)
Hibernate 5.2.2及更低版本不会发生这种情况.
这并没有解决这个问题:什么是gradle缺少映射休眠?.
这是我的用户类:
@Entity
@XmlRootElement
@Table(name = "user")
public class User extends EntityBase {
// some attributes
}
Run Code Online (Sandbox Code Playgroud)
和我的EntityBase类:
@XmlRootElement
@XmlAccessorType(value = XmlAccessType.NONE)
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "@class")
public abstract class EntityBase {
/**
* The entity's UUID.
*/
@Id
@XmlAttribute
private String uuid;
public EntityBase() {
uuid = UUID.randomUUID().toString();
} …Run Code Online (Sandbox Code Playgroud) 我知道我可以使用工具箱在 Scala 中编译单个“片段”,如下所示:
import scala.reflect.runtime.universe
import scala.tools.reflect.ToolBox
object Compiler {
val tb = universe.runtimeMirror(getClass.getClassLoader).mkToolBox()
def main(args: Array[String]): Unit = {
tb.eval(tb.parse("""println("hello!")"""))
}
}
Run Code Online (Sandbox Code Playgroud)
有什么方法可以编译不仅仅是“片段”,即相互引用的类?像这样:
import scala.reflect.runtime.universe
import scala.tools.reflect.ToolBox
object Compiler {
private val tb = universe.runtimeMirror(getClass.getClassLoader).mkToolBox()
val a: String =
"""
|package pkg {
|
|class A {
|def compute(): Int = 42
|}}
""".stripMargin
val b: String =
"""
|import pkg._
|
|class B {
|def fun(): Unit = {
| new A().compute()
|}
|}
""".stripMargin
def main(args: Array[String]): …Run Code Online (Sandbox Code Playgroud) 我想避免冗余,因此得到了一个包含以下内容的“共享”项目:
plugins {
id "org.flywaydb.flyway" version "4.2.0"
}
repositories {
mavenCentral()
jcenter()
}
apply plugin: "java"
dependencies {
compile "commons-io:commons-io:2.4"
// ...
}
Run Code Online (Sandbox Code Playgroud)
然后,我还有一些常规项目,它们可以从共享项目中继承编译依赖关系,如下所示:
apply plugin: "java"
repositories {
mavenCentral()
jcenter()
}
dependencies {
compile project(":shared")
testCompile project(":shared")
}
Run Code Online (Sandbox Code Playgroud)
有什么方法可以使我的常规项目继承插件块或实际插件?
我正在开发一个项目,我们正在使用TestNG和JUnit进行测试.
不幸的是,在编写TestNG测试时,他们不会在JaCoCo Coverage报告中考虑.
我写了一个testng.gradle文件,我将其包含在每个build.gradle文件中(这是一个多模块项目):
task testNG(type: Test) { useTestNG() }
test.dependsOn testNG
Run Code Online (Sandbox Code Playgroud)
JUnit和TestNG测试都以这种方式工作.
如果我写testng.gradle这样的话:
test {
useTestNG()
}
Run Code Online (Sandbox Code Playgroud)
JaCoCo工作正常,但显然只有TestNG测试才能执行.
我该如何解决?这是Gradle的JaCoCo插件中的错误吗?
gradle ×3
java ×2
flyway ×1
hibernate ×1
jacoco ×1
jpa ×1
junit ×1
multi-module ×1
reflection ×1
runtime ×1
scala ×1
subproject ×1
testng ×1