Ask Your Question
3

When converting build.gradle to build.gradle.kts, how can I avoid encountering an error such as "Unresolved reference: artifactId"?

asked 2023-06-08 02:28:51 +0000

plato gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-06-08 02:37:01 +0000

djk gravatar image

When converting from build.gradle to build.gradle.kts, you need to pay attention to the syntax differences between the two.

To avoid the "Unresolved reference" error, make sure you update the syntax of the variable references to their Kotlin equivalent. For example, instead of using "artifactId" in build.gradle, use "project.artifactId" in build.gradle.kts.

Here's an example of the syntax difference:

build.gradle:

group = 'com.example'
version = '1.0.0'
archivesBaseName = 'my-app'

build.gradle.kts:

group = "com.example"
version = "1.0.0"
project.archivesBaseName.set("my-app")

Note that in build.gradle.kts, we're accessing the archivesBaseName property as a function call on the project object. This is because gradle.kts is more strongly typed than gradle and requires this additional syntax.

In general, make sure to check the Gradle documentation for the specific syntax changes when converting your build scripts.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-08 02:28:51 +0000

Seen: 14 times

Last updated: Jun 08 '23