【问题标题】:How perform OpenJPA Enhancement when using Gradle?使用 Gradle 时如何执行 OpenJPA 增强?
【发布时间】:2015-03-05 21:45:01
【问题描述】:

我已经尝试过这个 gradle 插件 https://github.com/schmutterer/gradle-openjpa,但它抱怨它找不到某些库并且不支持提供的编译,这使得它对我来说无论如何都无法使用。

我也尝试过调用 ANT 任务,我最近的尝试是抛出:

Caused by: C:\Work_Java\workspace\PaxHoldRelease\jpa_enhance.xml:5: taskdef class org.apache.openjpa.ant.PCEnhancerTask cannot be found

build.grade

apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'ear'

// Java compilier compliance level
sourceCompatibility = 1.7
targetCompatibility = 1.7

repositories {
    mavenLocal()
    mavenCentral()
}    

ant.importBuild 'jpa_enhance.xml'
war.dependsOn enhance

dependencies {
    // Ensure ear plugin gets war file
    deploy files(war)

    providedCompile 'javax.servlet:javax.servlet-api:3.0.1'
    compile 'javax.websocket:javax.websocket-api:1.1'  

    compile 'org.glassfish.jersey.containers:jersey-container-servlet:2.16'
    compile 'com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:2.5.1'
    compile 'org.glassfish:javax.json:1.0.4'

    providedCompile 'org.apache.openjpa:openjpa:2.2.2'

    providedCompile 'com.sybase:jconn3:6.05'
    providedCompile files('libs/sqljdbc4-3.0.jar')
} 

jpa_enhance.xml

这是一长串尝试中的最新版本,可能完全是垃圾,因为我只是在绝望中撕掉了所有东西:-(

<project>
    <target name="enhance">
        <taskdef name="openjpac" classname="org.apache.openjpa.ant.PCEnhancerTask"/>

        <!-- invoke enhancer on all .java files below the model directory -->
        <openjpac>
        </openjpac>

        <echo message="Enhancing complete!"/>
    </target>
</project>

【问题讨论】:

    标签: ant gradle openjpa


    【解决方案1】:

    试试这个 Andrew - 我松散地将这个 gradle 建立在 S.O.由另一个成员(用于 DataNucleus 增强器)。

    请注意,您需要修改实体文件(包括/排除)以指向您特定的“成为/不成为”增强型 Java 源文件。此外,这种方法假定类路径派生自您的父 build.gradle。

    
    task openJPAEnhance {
        description "Enhance JPA model classes using OpenJPA Enhancer"
        dependsOn compileJava
    
        doLast {
            // define the entity classes
            def entityFiles = fileTree(sourceSets.main.output.classesDir).matching {
                include 'org/foo/mypkg/entity/*.class'
                exclude 'org/foo/mypkg/entity/DoNotEnhance.class'
            }
    
            println "Enhancing with OpenJPA, the following files..."
            entityFiles.getFiles().each {
                println it
            }
    
            // define Ant task for Enhancer
            ant.taskdef(
                name : 'openjpac',
                classpath : sourceSets.main.runtimeClasspath.asPath,
                classname : 'org.apache.openjpa.ant.PCEnhancerTask'
            )
    
            // Run the OpenJPA Enhancer as an Ant task
            //   - see OpenJPA 'PCEnhancerTask' for supported arguments
            //   - this invocation of the enhancer adds support for a default-ctor
            //   - as well as ensuring JPA property use is valid.
            ant.openjpac(
                classpath: sourceSets.main.runtimeClasspath.asPath,
                addDefaultConstructor: true,
                enforcePropertyRestrictions: true) {
                entityFiles.addToAntBuilder(ant, 'fileset', FileCollection.AntType.FileSet)
            }
        }
    }
    
    

    我希望这会有所帮助,编写第一个 gradle 脚本的人并不介意我们将它(从 DataNucleus)重新用于 OpenJPA。

    【讨论】:

      猜你喜欢
      • 2017-06-06
      • 1970-01-01
      • 2012-01-24
      • 2021-06-02
      • 1970-01-01
      • 2021-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多