Skip to content
This repository has been archived by the owner on Aug 19, 2020. It is now read-only.

Shared Constants in the Kotlin Script #1358

Closed
imanushin opened this issue Mar 11, 2019 · 3 comments
Closed

Shared Constants in the Kotlin Script #1358

imanushin opened this issue Mar 11, 2019 · 3 comments

Comments

@imanushin
Copy link

Unable to use shared constants (or shared properties) with Kotlin Script in Gradle.

Expected Behavior

As project developer I can:

  • Create object (in Kotlin terms) with list of the shared constants (such as project version, list of dependency versions, etc.). Or possible any contruction, which can be injected by simple into the all projects.
  • Use this object across all other kts files with compile-time check.
  • As a result I can use dependency string line implementation(group="org.jetbrains.kotlin", name= "kotlin-stdlib", version=Shared.KotlinVersion)

Current Behavior

It is unable simple to share common constants between kts files, becaue of the following issues:

  • It is unable to simple create object (or any other Java/Kotlin type) in the one project (for example - in root project) and use it in the another.
  • I can create buildSrc, which requires a lot of non-trivial constructs to work in isolation with public repositories (e.g. we use own Artifactory, instead of direct plugin download).
  • There are monstrous constructions for property usage, which can be checked here and here. I'd like to have simple insertion with compile-time checks.

Context

I'd like to achieve:

  • All project and plugin dependency versions are extract to the simple file.
  • All dependency constants can be used without boilerplate copy-pasting code (for example - Groovy does not require this)

Steps to Reproduce (for bugs)

Can be checked here or here

Your Environment

n/a

@eskatos
Copy link
Member

eskatos commented Apr 25, 2019

Thanks for the report @imanushin

Using buildSrc or an included build is the canonical way to share types including constants to make them available to all your build scripts. It currently requires some ceremony but this will be made easier over time.

Note that extra properties are very dynamic by nature, a shared static Kotlin object will bring much nicer benefits.

@eskatos eskatos closed this as completed Apr 25, 2019
@imanushin
Copy link
Author

@eskatos , however how can I simple share constant (for example - kotlin version) in buildSrc scripts (to have ability to apply plugin) and in the main gradle scripts?

As I found, buildSrc scripts ignores shared object, which is created inside it. Therefore I could not create the following:

  • Create N projects
  • Create shared script in the buildSrc, which will install some plugin (for example - kotlin plugin)

Last item require kotlin version determine in the buildSrc folder, which is difficult for now.

@eskatos
Copy link
Member

eskatos commented Apr 25, 2019

@imanushin, please see #1320, especially #1320 (comment)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants