Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

479
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda