This message was deleted.
# configuration-cache
s
This message was deleted.
v
I do something similar. Have a build service that logs the lines. Then`get()` it at configuration time, so it is evaluated immediately when configuration is done and also register it as task listener, then it is executed as soon as the first task finished. I'm on mobile so cannot send code right now, but maybe the information is enough for you to achieve your goal, otherwise I can help you further later.
c
Great info, thx, will implement that.
v
Like this in the build service:
Copy code
abstract class TheService : BuildService<None>, OperationCompletionListener {
    init {
        println(
            // have an extra blank line in case the caret is not at the beginning of a line
            """

                ##teamcity[setParameter name='version' value='$version']
            """.trimIndent()
        )
    }

    override fun onFinish(event: FinishEvent?) {
        // intentionally empty, the constructor does the work so that it is done
        // as early as possible; the OperationCompletionListener is just implemented
        // so that this service gets instantiated as soon as the first task finished
        // if it was not created during configuration phase due to configuration cache
    }
}
and something like this at configuration time:
Copy code
@get:Inject
protected abstract val buildServiceRegistry: BuildServiceRegistry

@get:Inject
protected abstract val buildEventsListenerRegistry: BuildEventsListenerRegistry

private val theService: Provider<TheService> = buildServiceRegistry.registerIfAbsent(
    "theService",
    TheService::class.java
) {
}

init {
    // if configuration phase is executed, create the service eagerly
    // otherwise it is created as soon as the first task finished if run on TeamCity
    theService.get()

    buildEventsListenerRegistry.onTaskCompletion(theService)
}
👍 1