Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

477
Visualizações
Get build time with Gradle Kotlin DSL

In my Gradle script's build task, I want to get the current timestamp whenever I build my project and save it to a file in my project's resource directory. If I understand correctly, I should be able to call Java methods to achieve this, something like (in Kotlin):

val timestamp = SimpleDateFormat("yyyy-MM-dd-HH:mm:ss").format(Date())

Attempting to import my script into IntelliJ fails with unresolved reference errors (SimpleDateFormat and Date).

Using the fully qualified name does not work either (java.util.Date); IntelliJ shows that it tries to treat java as the java plugin.

My build.gradle.kts looks like this:

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 ...

How can I properly use those references? Am I missing a specific plugin, or do I need to be taking a whole different approach?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Have you tried adding an import statement to the top of your build.gradle.kts file?

Most likely java refers to the identically named task, because you're inside the tasks scope.

import java.util.Date
import java.text.SimpleDateFormat

plugins {
   ...
}

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

... other configuration ...

Instead of using the java.util.Date class, I recommend taking a look at the newer java.time.Instant class instead.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda