将ANOW J 1.8.1升级到1.9.8并与Gradle 7 + Java 11集成无法找到ANOW jrt.jar

7gcisfzg  于 2023-11-18  发布在  Java
关注(0)|答案(1)|浏览(125)

我正在将基于Java 8的spring代码库(gradle项目)升级到Java 11。该项目确实包含AOP代码(https://en.wikipedia.org/wiki/Aspect-oriented_programming),并且依赖于这些依赖项

org.springframework:spring-aspects:4.3.27.RELEASE
org.aspectj:aspectjtools:1.8.1
org.aspectj:aspectjrt:1.8.1

字符串
升级到1.9.8后的上述依赖关系:

dependencies {
    ajc 'org.aspectj:aspectjtools:1.9.8'
    implementation 'javax.persistence:persistence-api:1.0'
    implementation 'org.aspectj:aspectjtools:1.9.8'
    implementation 'org.aspectj:aspectjrt:1.9.8'
    aspects 'javax.persistence:persistence-api:1.0'

    aspects "org.springframework:spring-aspects:${springVersion}"
    aspects "org.springframework:spring-tx:${springVersion}"
    aspects "org.springframework:spring-orm:${springVersion}"


基于以下文档,ANOW J 1.8.x与java 8+不兼容:https://github.com/eclipse-aspectj/aspectj/blob/master/docs/dist/doc/JavaVersionCompatibility.md
Java 17是我们计划最终升级到的版本。官方文档关于Apache J 1.9.8及其支持:https://htmlpreview.github.io/?https://github.com/kriegaex/org.aspectj/blob/4b9d86acd096e5ee9e108ff0a450c420c880b6ea/docs/dist/doc/README-198.html
成功将gradle 5升级到gradle 7后,尝试运行gradlew clean build失败,出现以下错误:

> Task :compileJava
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/someDir/someService/src/main/java/someCode.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

[ant:iajc] [warning] couldn't find aspectjrt.jar on classpath, checked: /Library/Java/JavaVirtualMachines/jdk-11.0.14.jdk/Contents/Home/lib/jrt-fs.jar:/Users/user/.gradle/caches/modules-2/files-2.1/javax.persistence/persistence-api/1.0/5725f57873e05e068803e2bf9d5a8ea3740ffec5/persistence-api-1.0.jar:/Users/user/.gradle/caches/modules-2/files-2.1/org.springframework/spring-aspects/5.3.19/a60d729e20daa34220b63be28d1b3cd20c1128e8/spring-aspects-5.3.19.jar:/Users/user/.gradle/caches/modules-2/files-2.1/org.springframework/spring-tx/5.3.19/f0b442718e67000845e8662ea10f138d7c47a3ae/spring-tx-5.3.19.jar:/Users/user/.gradle/caches/modules-2/files-2.1/org.springframework/spring-orm/5.3.19/963b297aed7a1f9252cf4d925e6178190448ec81/spring-orm-5.3.19.jar:/Users/user/.gradle/caches/modules-2/files-2.1/javax.persistence/persistence-api/1.0/5725f57873e05e068803e2bf9d5a8ea3740ffec5/persistence-api-1.0.jar:/Users/user/.gradle/caches/modules-2/files-2.1/org.springframework/spring-aspects/5.3.19/a60d729e20daa34220b63be28d1b3cd20c1128e8/spring-aspects-5.3.19.jar:/Users/user/.gradle/caches/modules-2/files-2.1/org.springframework/spring-tx/5.3.19/f0b442718e67000845e8662ea10f138d7c47a3ae/spring-tx-5.3.19.jar:/Users/user/.gradle/caches/modules-2/files-2.1/org.springframework/spring-orm/5.3.19/963b297aed7a1f9252cf4d925e6178190448ec81/spring-orm-5.3.19.jar
[ant:iajc]
[ant:iajc] [error] can't determine implemented interfaces of missing type org.springframework.beans.factory.DisposableBean
[ant:iajc] when batch building BuildConfig[null] #Files=180 AopXmls=#0
[ant:iajc]  [Xlint:cantFindType]
[ant:iajc]
[ant:iajc] [error] can't determine implemented interfaces of missing type org.springframework.beans.factory.BeanFactoryAware
[ant:iajc] when batch building BuildConfig[null] #Files=180 AopXmls=#0
[ant:iajc]  [Xlint:cantFindType]
[ant:iajc]
[ant:iajc] [error] can't determine implemented interfaces of missing type org.springframework.beans.factory.InitializingBean
[ant:iajc] when batch building BuildConfig[null] #Files=180 AopXmls=#0
[ant:iajc]  [Xlint:cantFindType]
[ant:iajc]
[ant:iajc] [error] can't determine superclass of missing type org.springframework.aop.interceptor.AsyncExecutionAspectSupport
[ant:iajc] when batch building BuildConfig[null] #Files=180 AopXmls=#0
[ant:iajc]  [Xlint:cantFindType]
[ant:iajc]
[ant:iajc] [error] can't determine superclass of missing type org.springframework.cache.interceptor.CacheAspectSupport
[ant:iajc] when batch building BuildConfig[null] #Files=180 AopXmls=#0
[ant:iajc]  [Xlint:cantFindType]
[ant:iajc]
[ant:iajc] [error] can't determine implemented interfaces of missing type org.springframework.beans.factory.DisposableBean
[ant:iajc] when batch building BuildConfig[null] #Files=180 AopXmls=#0
[ant:iajc]  [Xlint:cantFindType]
[ant:iajc]
[ant:iajc] [error] can't determine implemented interfaces of missing type org.springframework.beans.factory.BeanFactoryAware
[ant:iajc] when batch building BuildConfig[null] #Files=180 AopXmls=#0
[ant:iajc]  [Xlint:cantFindType]
[ant:iajc]
[ant:iajc] [error] can't determine implemented interfaces of missing type org.springframework.beans.factory.InitializingBean
[ant:iajc] when batch building BuildConfig[null] #Files=180 AopXmls=#0
[ant:iajc]  [Xlint:cantFindType]
[ant:iajc]
[ant:iajc] [error] can't determine implemented interfaces of missing type org.springframework.beans.factory.DisposableBean
[ant:iajc] when batch building BuildConfig[null] #Files=180 AopXmls=#0
[ant:iajc]  [Xlint:cantFindType]
[ant:iajc]
[ant:iajc] [error] classpath error: unable to find org.aspectj.lang.JoinPoint (check that aspectjrt.jar is in your classpath)
[ant:iajc]
[ant:iajc]
[ant:iajc] 10 errors, 1 warning


我已经仔细检查并验证了aspectjrt.jar存在于我的主.gradle目录中:

/Users/user/.gradle/caches/modules-2/files-2.1/org.aspectj/aspectjrt/1.9.8/7a5d13787d5268d415055eba51024fb7348fc533/aspectjrt-1.9.8.jar


然而,我现有的build.gradle文件似乎没有检查这个目录的某些原因.(我怀疑这是根本原因在这里)
我当前的build.gradle设置如下:

configurations.all {
    transitive = false
}

compileJava {
    doLast {
        ant.taskdef( resource:"org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties", classpath: configurations.ajc.asPath)
        ant.iajc(
                source:"1.11",
                target:"1.11",
                destDir:sourceSets.main.output.classesDirs.getAsPath(),
                maxmem:"512m", fork:"true",
                aspectPath:configurations.aspects.asPath,
                sourceRootCopyFilter:"**/*.java",
                classpath:"${configurations.compile.asPath}") {
                    sourceroots {
                        sourceSets.main.java.srcDirs.each {
                            srcDir ->
                            pathelement(location:srcDir.absolutePath)
                        }
                    }
        }
    }
}

configurations{
    ajc
    aspects
    aspectCompile
    compile {
        extendsFrom aspects
    }
}
....

task sourcesJar(type: Jar) {
    from sourceSets.main.allSource
    classifier = 'sources'
}


我已经在官方文档上检查了AjcTask(iajc)安装的所有细节,不幸的是,这些步骤都是为maven项目编写的:https://eclipse.dev/aspectj/doc/next/devguide/printable.html#antTasks-install
如果有人碰巧知道解决这个问题的链接/指南,将真正感谢分享!

s2j5cfk0

s2j5cfk01#

我已经仔细检查并验证了aspectjrt.jar存在于我的主.gradle目录中
好吧,这可能是真的,但显然它不在Ant任务的类路径上(添加了换行符以限制水平滚动):

[ant:iajc] [warning] couldn't find aspectjrt.jar on classpath, checked
  /Library/Java/JavaVirtualMachines/jdk-11.0.14.jdk/Contents/Home/lib/jrt-fs.jar
  /Users/user/.gradle/caches/modules-2/files-2.1/javax.persistence/persistence-api/1.0/5725f57873e05e068803e2bf9d5a8ea3740ffec5/persistence-api-1.0.jar
  /Users/user/.gradle/caches/modules-2/files-2.1/org.springframework/spring-aspects/5.3.19/a60d729e20daa34220b63be28d1b3cd20c1128e8/spring-aspects-5.3.19.jar
  /Users/user/.gradle/caches/modules-2/files-2.1/org.springframework/spring-tx/5.3.19/f0b442718e67000845e8662ea10f138d7c47a3ae/spring-tx-5.3.19.jar
  /Users/user/.gradle/caches/modules-2/files-2.1/org.springframework/spring-orm/5.3.19/963b297aed7a1f9252cf4d925e6178190448ec81/spring-orm-5.3.19.jar
  /Users/user/.gradle/caches/modules-2/files-2.1/javax.persistence/persistence-api/1.0/5725f57873e05e068803e2bf9d5a8ea3740ffec5/persistence-api-1.0.jar
  /Users/user/.gradle/caches/modules-2/files-2.1/org.springframework/spring-aspects/5.3.19/a60d729e20daa34220b63be28d1b3cd20c1128e8/spring-aspects-5.3.19.jar
  /Users/user/.gradle/caches/modules-2/files-2.1/org.springframework/spring-tx/5.3.19/f0b442718e67000845e8662ea10f138d7c47a3ae/spring-tx-5.3.19.jar
  /Users/user/.gradle/caches/modules-2/files-2.1/org.springframework/spring-orm/5.3.19/963b297aed7a1f9252cf4d925e6178190448ec81/spring-orm-5.3.19.jar

字符串
修好它你就没事了
顺便说一句,为什么你使用Gradle中的一个古老的Ant任务,而不是像Freefair这样的东西?

相关问题