小编wys*_*koj的帖子

使用 Gradle Kotlin DSL 获取构建时间

在我的 Gradle 脚本的build任务中,我希望在构建项目时获取当前时间戳并将其保存到项目资源目录中的文件中。如果我理解正确的话,我应该能够调用 Java 方法来实现这一点,例如(在 Kotlin 中):

val timestamp = SimpleDateFormat("yyyy-MM-dd-HH:mm:ss").format(Date())
Run Code Online (Sandbox Code Playgroud)

尝试将我的脚本导入 IntelliJ 失败,并出现未解决的引用错误(SimpleDateFormatDate)。

使用完全限定名称也不起作用 ( java.util.Date);IntelliJ 表明它尝试将其视为java插件java

我的build.gradle.kts看起来像这样:

plugins {
    `java-library`
    kotlin("jvm") version "1.6.10"
    java
    idea
    application
    ... other plugins ...
    
}

tasks.build {
    val timestamp = SimpleDateFormat("MM-dd-yyyy_hh-mm").format(Date())
}

... other configuration ...
Run Code Online (Sandbox Code Playgroud)

我该如何正确使用这些参考资料?我是否缺少特定的插件,或者我是否需要采取完全不同的方法?

java gradle kotlin gradle-kotlin-dsl

7
推荐指数
1
解决办法
2968
查看次数

无法通过 Docs API 向新的 Google Doc 添加文本

我的程序正在创建文档,每个文档都有需要输入的文本。任何InsertTextRequest调用调用的尝试都会引发错误。

List<Request> requests = new ArrayList<>();

requests.add(new Request().setInsertText(new InsertTextRequest()
                .setText("Simple test.")
                .setLocation(new Location().setIndex(0))));

BatchUpdateDocumentRequest body = new BatchUpdateDocumentRequest()
                .setRequests(requests);

BatchUpdateDocumentResponse response = docService.documents()
                .batchUpdate(file.getId(), body).execute();
Run Code Online (Sandbox Code Playgroud)
Exception in thread "main" com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
{
  "code" : 400,
  "errors" : [ {
    "domain" : "global",
    "message" : "Invalid requests[0].insertText: The insertion index must be inside the bounds of an existing paragraph. You can still create new paragraphs by inserting newlines.",
    "reason" : "badRequest"
  } ],
  "message" : "Invalid requests[0].insertText: …
Run Code Online (Sandbox Code Playgroud)

java google-docs-api

4
推荐指数
1
解决办法
1355
查看次数