JPA Static Metamodel Generator的正确gradle设置是什么?

时间:2016-07-12 22:56:57

标签: java hibernate jpa

我正在尝试使用JPA Static Metamodel生成器。我发现a tutorial page解释了如何在Gradle中进行设置。我还发现a stackoverflow comment表示使用相同的类路径。它是:

classpath "gradle.plugin.at.comm_unity.gradle.plugins:jpamodelgen-plugin:1.1.1"

但是,当我尝试使用它时,我得到了一个gradle构建错误:

Error:Could not find gradle.plugin.at.comm_unity.gradle.plugins:jpamodelgen-plugin:1.1.1.
Searched in the following locations:
https://repo1.maven.org/maven2/gradle/plugin/at/comm_unity/gradle/plugins/jpamodelgen-plugin/1.1.1/jpamodelgen-plugin-1.1.1.pom
https://repo1.maven.org/maven2/gradle/plugin/at/comm_unity/gradle/plugins/jpamodelgen-plugin/1.1.1/jpamodelgen-plugin-1.1.1.jar
https://jcenter.bintray.com/gradle/plugin/at/comm_unity/gradle/plugins/jpamodelgen-plugin/1.1.1/jpamodelgen-plugin-1.1.1.pom
https://jcenter.bintray.com/gradle/plugin/at/comm_unity/gradle/plugins/jpamodelgen-plugin/1.1.1/jpamodelgen-plugin-1.1.1.jar

有什么问题?这个位置是否已过时?如果是这样,新的是什么?

2 个答案:

答案 0 :(得分:1)

事实证明原始教程页面确实有答案,它只是在示例中注释掉了。必须指定正确的maven存储库。这对我有用:

repositories {
    maven {
        url "https://plugins.gradle.org/m2/"
    }
}

答案 1 :(得分:0)

首先声明gradle插件库:

buildscript {
   repositories {
      jcenter()
      maven {
         url "https://plugins.gradle.org/m2/"
      }
      //... other repositories
   }

   dependencies {
      classpath "at.comm_unity.gradle.plugins.jpamodelgen:plugin:1.1.2"
   }
} 

申请gradle插件:

apply plugin: "com.github.iboyko.gradle.plugins.jpamodelgen"

jpaModelgen {
    library = "org.hibernate:hibernate-jpamodelgen:4.3.8.Final"
    jpaModelgenSourcesDir = "src/src/java"
}

compileJava.options.compilerArgs += ["-proc:none"]

配置的最后一行应始终存在,否则它将删除原始源代码。