Kotlin: 未解决的引用:javaClass

18

希望有人能够遇到我在构建java/Kotlin项目时遇到的问题。该项目是Java和Kotlin相互操作,具有以下版本:

  • Jdk 1.7
  • Kotlin 0.9.66
  • Gradle (wrapper) 2.0

在我进行一些更改之前,Kotlin编译良好,例如将一些Java类转换为等效的Kotlin版本。

这里是我看到的错误:

  c:\projects\myproject>gradlew  :java:workspace:models:compileKotlin  --stacktrace     :java:workspace:models:compileKotlin

w: Annotations path entry points to a non-existent location:
C:\projects\myproject\java\workspace\models\annotations

e: C:\projects\CustomerProfileEmail.kt: (15, 32): Unresolved reference: toLowerCase
e: C:\projects\CustomerProfilePhone.kt: (34, 22): Unresolved reference: equalsIgnoreCase
e: C:\projects\Account.kt: (17, 21): Unresolved reference: javaClass
e: C:\projects\Account.kt: (18, 21): Unresolved reference: javaClass
e: C:\projects\Account.kt: (31, 15): Unresolved reference: indexOf
e: C:\projects\Account.kt: (35, 15): Expression 'length' of type 'kotlin.Int' cannot be invoked as a function. The function invoke() is not found
e: C:\projects\Account.kt: (39, 15): Expression 'length' of type 'kotlin.Int' cannot be invoked as a function. The function invoke() is not found
e: C:\projects\Balance.kt: (10, 21): Unresolved reference: javaClass
e: C:\projects\Balances.kt: (12, 21): Unresolved reference: firstOrNull
e: C:\projects\Balances.kt: (12, 35): Cannot infer a type for this parameter. To specify it explicitly use the {(p : Type) -> ...} notation
e: C:\projects\Debit.kt: (7, 12):Unresolved reference: javaClass
e: C:\projects\ProgramR.kt: (12, 21): Unresolved reference: javaClass
e: C:\projects\ProgramR.kt: (13, 21): Unresolved reference: javaClass
e: C:\projects\Transaction.kt: (7, 12): Unresolved reference: javaClass
e: C:\projects\Transaction.kt: (7, 40): Unresolved reference: javaClass
e: C:\projects\Adjustment.kt: (13,21): Unresolved reference: javaClass
e: C:\projects\Reward.kt: (12, 24): Unresolved reference: javaClass
:java:workspace:models:compileKotlin FAILED

FAILURE: Build failed with an exception.

这里是源代码的一个例子:

import javax.xml.bind.annotation.*

XmlAccessorType(XmlAccessType.FIELD)
XmlType
XmlSeeAlso(javaClass<LoyaltyCredit>(), javaClass<Debit>())
public open class Transaction: TransactionParent(){
    public var account: Account? = null
    public var balances: Balances? = null
    public var rewards: Rewards? = null
}

Gradle脚本

repositories {
    mavenCentral()
}

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.connorgarvey.gradle:gradle-grails-wrapper:1.0'
        classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:0.9.66'
        classpath 'org.jetbrains.kotlin:kotlin-stdlib:0.9.66'
    }
}

apply from: 'build/includes.gradle'

我已经看过这个:https://devnet.jetbrains.net/message/5478050,但没有帮助。

非常感谢任何帮助!


如果您找到了一个解决方案,但它并没有直接在被接受的答案中提到,请通过编辑您的问题来描述您是如何解决这个问题的。否则,其他人可能会看到这个问题,但不知道“参考资料帮助了我朝着正确的方向寻找”实际上意味着什么,以便识别解决方案。 - Jayson Minard
1个回答

6

将您的脚本与Kotlin有关Gradle的参考进行比较。

Kotlin Stdlib依赖项应该在另一个范围内,而不是buildscript。 此外,应该使用apply plugin来应用Kotlin插件。


谢谢你的提示。我正在处理一个非常复杂的脚本。即使我有与参考文献相同的脚本,它也会在导入的脚本行中被覆盖。这个参考文献帮助我朝着正确的方向寻找答案! - SteedsOfWar
@WolfBane 请更新您的问题或在此处添加评论,说明您找到的实际解决方案。 - Jayson Minard

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接