Kotlin在编译时未解析引用

时间:2017-11-20 10:26:52

标签: maven kotlin

我几天前正在研究一个项目并且它正在工作,我今天又回来了,它不再编译,但据我所知,我没有改变任何东西......

这是文件:

package windall.console.account.api.persistence

import com.fasterxml.jackson.annotation.JsonIgnore
import windall.console.account.api.dtos.PaymentDto
import windall.console.account.api.model.Tenant
import java.time.LocalDateTime
import javax.persistence.Column
import javax.persistence.Entity
import javax.persistence.GeneratedValue
import javax.persistence.Id
import javax.persistence.JoinColumn
import javax.persistence.ManyToOne

@Entity
data class Receipt (

        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        val id: Long? = null,

        val amount: Long,

        @JsonIgnore
        @ManyToOne(fetch = FetchType.EAGER)
        @JoinColumn(name = "tenant_id")
        val tenant: Tenant? = null,

        @Column(name = "payment_datetime")
        val paymentDateTime: LocalDateTime = LocalDateTime.now()

) {

    @Suppress("unused")
    private constructor(): this(amount = 0)

    constructor(dto: PaymentDto, tenant: Tenant) : this(amount = dto.amount, tenant = tenant)

}

以下是我在maven构建中遇到的错误:

> [ERROR] Failed to execute goal org.jetbrains.kotlin:kotlin-maven-plugin:1.1.60:compile (compile) on project api: Compilation failure: Compilation failure:
> [ERROR] C:\workspace\windall.console.account.api\src\main\kotlin\windall\console\account\api\models\Receipt.kt:[18,30] Unresolved reference: GenerationType
> [ERROR] C:\workspace\windall.console.account.api\src\main\kotlin\windall\console\account\api\models\Receipt.kt:[18,30] An annotation parameter must be a compile-time constant
> [ERROR] C:\workspace\windall.console.account.api\src\main\kotlin\windall\console\account\api\models\Receipt.kt:[24,22] Unresolved reference: FetchType
> [ERROR] C:\workspace\windall.console.account.api\src\main\kotlin\windall\console\account\api\models\Receipt.kt:[24,22] An annotation parameter must be a compile-time constant

任何帮助都会非常棒:)因为我似乎无法找到导致这些错误的任何可能原因,我的IDE也没有强调任何问题......

这也是我的pom以防万一

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>windall.console.account</groupId>
    <artifactId>api</artifactId>
    <version>1.0.0.RELEASE</version>
    <packaging>jar</packaging>

    <name>windall.console.account.api</name>
    <description>Mucking around</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.3.RELEASE</version>
    </parent>

    <properties>
        <!--kotlin.compiler.incremental>true</kotlin.compiler.incremental-->
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <kotlin.version>1.1.60</kotlin.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-stdlib-jre8</artifactId>
            <version>${kotlin.version}</version>
        </dependency>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-reflect</artifactId>
            <version>${kotlin.version}</version>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.datatype</groupId>
            <artifactId>jackson-datatype-jsr310</artifactId>
            <version>2.9.2</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.6.1</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.6.1</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-test-junit</artifactId>
            <version>${kotlin.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java8</artifactId>
            <version>1.2.5</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-spring</artifactId>
            <version>1.2.5</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>1.2.5</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
        <testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <artifactId>kotlin-maven-plugin</artifactId>
                <groupId>org.jetbrains.kotlin</groupId>
                <version>${kotlin.version}</version>
                <configuration>
                    <compilerPlugins>
                        <plugin>spring</plugin>
                    </compilerPlugins>
                    <jvmTarget>1.8</jvmTarget>
                </configuration>
                <executions>
                    <execution>
                        <id>compile</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>test-compile</id>
                        <phase>test-compile</phase>
                        <goals>
                            <goal>test-compile</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.jetbrains.kotlin</groupId>
                        <artifactId>kotlin-maven-allopen</artifactId>
                        <version>${kotlin.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>


</project>

1 个答案:

答案 0 :(得分:0)

我错过了导入

import javax.persistence.GenerationType
import javax.persistence.FetchType

结果证明eclipse不会识别Kotlin中注释参数中使用的类,因此,清理导入任务将其删除......

相关问题