te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>Why does IntelliJ report compile errors when the Gradle wrapper doesnt? - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Why does IntelliJ report compile errors when the Gradle wrapper doesnt? - Stack Overflow

programmeradmin4浏览0评论

I have two separate multi-projects. One is for the backend on the server (Amazon/Tomcat), the other for the frontend. In the backend project, most of the projects are written in Java. One sub-project is written in Kotlin. Part of the code here is used by both the backend and frontend. It should be using JVM for the backend, and export a JavaScript file to be bundled with the frontend project.

When I build the projects using the commandline Gradle wrapper, it builds successfully. When I build the project in IntelliJ (2024.3.2.2), the inspection tool reports compile errors. I've created a minimum example to illustrate one such compile error. I'm using the following java --version

openjdk 21.0.6 2025-01-21 LTS
OpenJDK Runtime Environment Corretto-21.0.6.7.1 (build 21.0.6+7-LTS)
OpenJDK 64-Bit Server VM Corretto-21.0.6.7.1 (build 21.0.6+7-LTS, mixed mode, sharing)

Project structure in this example:

root 
|-> JavaProject 
|   |-> src/javaPackage
|   |       |-> JavaFile.java
|   |-> build.gradle.kts
|-> KotlinProjct
|   |-> src/commonMain/kotlin
|   |                  |-> KotlinFile.kt
|   |-> build.gradle.kts
|-> build.gradle.kts
|-> settings.gradle.kts 

settings.gradle.kts

pluginManagement {
    plugins {
        `kotlin-dsl`
    }
}

include("JavaProject")
include("KotlinProject")


Root gradle.build.kts

import .jetbrains.kotlin.gradle.dsl.JvmTarget
import .jetbrains.kotlin.gradle.dsl.KotlinVersion

plugins {
    kotlin("multiplatform") version "2.1.10" apply false
    java
}

allprojects {
    tasks.withType<JavaCompile> {
        sourceCompatibility = "21"
        targetCompatibility = "21"
    }

    tasks.withType<.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
        compilerOptions {
            languageVersion.set(KotlinVersion.KOTLIN_2_1)
            apiVersion.set(KotlinVersion.KOTLIN_2_1)
            jvmTarget.set(JvmTarget.JVM_21)
        }
    }

    tasks.withType<Wrapper> {
        gradleVersion = "8.12.1"
        distributionType = Wrapper.DistributionType.ALL
    }
}

KotlinProject/build.gradle.kts

plugins {
    kotlin("multiplatform")
}

repositories {
    mavenCentral()
}

kotlin {
    jvm {
        withJava()
    }

    js(IR) {
        browser {
        }
        binaries.executable()
    }
}

JavaProject/build.gradle.kts

plugins {
    `java-library`
}

repositories {
    mavenCentral()
}

dependencies {
    implementation(project(":KotlinProject"))
}

sourceSets {
    main {
        java {
            srcDirs("src")
        }
        resources {
            srcDirs("src")
        }
        output.setResourcesDir(file("build/classes/java/main"))
        java.destinationDirectory.set(file("build/classes/java/main"))
    }
}

task<JavaExec>("RunJavaMain") {
    mainClass = "javaPackage.JavaFile"
    classpath = sourceSets["main"].runtimeClasspath
}

KotlinFile.kt

package kotlinPackage

import kotlin.js.JsName
import kotlin.jvm.JvmField
import kotlin.jvm.JvmStatic

data class KotlinObject(
    @JvmField
    val string : String
)
{
    companion object
    {
        @JvmStatic
        @JsName("parse")
        fun parse(input : String) : KotlinObject
        {
            return KotlinObject(input)
        }
    }
}

JavaFile.java

package javaPackage;

import kotlinPackage.KotlinObject;

class JavaFile
{
    public static void main(String[] args)
    {
        KotlinObject item = KotlinObject.parse("Foo");
    }
}

When I build this in IntelliJ, I get a rather funny compile error on ("Foo"):

Required type:
String
Provided:
String

The more detailed message is

'parse([email protected] String)' in 'kotlinPackage.KotlinObject' cannot be applied to '(java.lang.String)'

This message does not appear if I build the project using the commandline Gradle wrapper:

./gradlew build

BUILD SUCCESSFUL in 923ms
30 actionable tasks: 3 executed, 27 up-to-date

./gradlew --version

------------------------------------------------------------
Gradle 8.12.1
------------------------------------------------------------

Build time:    2025-01-24 12:55:12 UTC
Revision:      0b1ee1ff81d1f4a26574ff4a362ac9180852b140

Kotlin:        2.0.21
Groovy:        3.0.22
Ant:           Apache Ant(TM) version 1.10.15 compiled on August 25 2024
Launcher JVM:  21.0.6 (Amazon Inc. 21.0.6+7-LTS)
Daemon JVM:    /usr/lib/jvm/java-21-amazon-corretto (no JDK specified, using current Java home)
OS:            Linux 6.8.0-52-generic amd64

Invalidate caches makes no difference.

If I comment out the following section in KotlinProject/build.gradle.kts

    js(IR) {
        browser {
        }
        binaries.executable()
    }

the compile error above disappears in IntelliJ for JavaFile.java, but then problems pop up with KotlinFile.kt instead:

Unresolved reference 'JsName'.

Regardless, this is not a fix; I need the JavaScript files for the frontend project.

I've ran tests on the real project (not the example above) when its built with the Gradle wrapper, and there appears to be no problems. In other words, this is some sort of false positive that only exists in IntelliJ.

There are a lot more issues than just the one above. I just created an example with one of the simplest, relevant cases that I could come up with.

发布评论

评论列表(0)

  1. 暂无评论