You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|_\<targetName\>_| Declares a particular target of a project. The names of available targets are listed in the [Targets](#targets) section. |
42
+
|`targets`| All targets of the project. |
43
+
|`presets`| All predefined targets. Use this for [configuring multiple predefined targets](#targets) at once. |
44
+
|`sourceSets`| Configures predefined and declares custom [source sets](#source-sets) of the project. |
45
+
|`compilerOptions`| Extension-level common [compiler options](gradle-compiler-options.md) that are used as defaults for all targets and shared source sets. To use it, add the following opt-in: `@OptIn(ExperimentalKotlinGradlePluginApi::class)`|
46
+
47
+
> The support for `compilerOptions {}` as a top-level block is [Experimental](components-stability.md#stability-levels-explained)
48
+
> and requires opt-in. It may be dropped or changed at any time. Use it only for evaluation purposes. We would appreciate
49
+
> your feedback on it in [YouTrack](https://kotl.in/issue).
50
+
>
51
+
{type="warning"}
45
52
46
53
## Targets
47
54
@@ -51,7 +58,7 @@ one of the supported platforms. Kotlin provides target presets for each platform
51
58
Each target can have one or more [compilations](#compilations). In addition to default compilations for
52
59
test and production purposes, you can [create custom compilations](multiplatform-configure-compilations.md#create-a-custom-compilation).
53
60
54
-
The targets of a multiplatform project are described in the corresponding blocks inside `kotlin`, for example, `jvm`, `android`, `iosArm64`.
61
+
The targets of a multiplatform project are described in the corresponding blocks inside `kotlin {}`, for example, `jvm`, `android`, `iosArm64`.
55
62
The complete list of available targets is the following:
56
63
57
64
<table>
@@ -118,13 +125,20 @@ Each target can have one or more [compilations](#compilations).
118
125
119
126
In any target block, you can use the following declarations:
|`attributes`| Attributes used for [disambiguating targets](multiplatform-set-up-targets.md#distinguish-several-targets-for-one-platform) for a single platform. |
124
-
|`preset`| The preset that the target has been created from, if any. |
125
-
|`platformType`| Designates the Kotlin platform of this target. Available values: `jvm`, `androidJvm`, `js`, `native`, `common`. |
126
-
|`artifactsTaskName`| The name of the task that builds the resulting artifacts of this target. |
127
-
|`components`| The components used to setup Gradle publications. |
|`attributes`| Attributes used for [disambiguating targets](multiplatform-set-up-targets.md#distinguish-several-targets-for-one-platform) for a single platform. |
131
+
|`preset`| The preset that the target has been created from, if any. |
132
+
|`platformType`| Designates the Kotlin platform of this target. Available values: `jvm`, `androidJvm`, `js`, `native`, `common`. |
133
+
|`artifactsTaskName`| The name of the task that builds the resulting artifacts of this target. |
134
+
|`components`| The components used to setup Gradle publications. |
135
+
|`compilerOptions`| The [compiler options](gradle-compiler-options.md) used for the target. This declaration overrides any `compilerOptions {}` configured at [top level](multiplatform-dsl-reference.md#top-level-blocks). To use it, add the following opt-in: `@OptIn(ExperimentalKotlinGradlePluginApi::class)`|
136
+
137
+
> The support for `compilerOptions {}` as a common target configuration is [Experimental](components-stability.md#stability-levels-explained)
138
+
> and requires opt-in. It may be dropped or changed at any time. Use it only for evaluation purposes. We would appreciate
139
+
> your feedback on it in [YouTrack](https://kotl.in/issue).
140
+
>
141
+
{type="warning"}
128
142
129
143
### JVM targets
130
144
@@ -149,7 +163,7 @@ kotlin {
149
163
150
164
### JavaScript targets
151
165
152
-
The `js` block describes the configuration of JavaScript targets. It can contain one of two blocks depending on the target execution environment:
166
+
The `js {}` block describes the configuration of JavaScript targets. It can contain one of two blocks depending on the target execution environment:
// Setup the Kotlin compiler options for the 'main' compilation:
730
-
jvmTarget.set(JvmTarget.JVM_1_8)
744
+
jvmTarget = JvmTarget.JVM_1_8
731
745
}
732
746
733
747
compilations.main.compileKotlinTask // get the Kotlin task 'compileKotlinJvm'
@@ -739,7 +753,7 @@ kotlin {
739
753
targets.all {
740
754
compilations.all {
741
755
compilerOptions.configure {
742
-
allWarningsAsError.set(true)
756
+
allWarningsAsErrors = true
743
757
}
744
758
}
745
759
}
@@ -749,9 +763,48 @@ kotlin {
749
763
</tab>
750
764
</tabs>
751
765
766
+
Alternatively, to configure compiler options that are common for all targets, you can use the `compilerOptions {}`[top-level block](multiplatform-dsl-reference.md#top-level-blocks):
767
+
768
+
<tabsgroup="build-script">
769
+
<tabtitle="Kotlin"group-key="kotlin">
770
+
771
+
```kotlin
772
+
kotlin {
773
+
774
+
// Configure all compilations of all targets:
775
+
@OptIn(ExperimentalKotlinGradlePluginApi::class)
776
+
compilerOptions {
777
+
allWarningsAsErrors.set(true)
778
+
}
779
+
}
780
+
```
781
+
782
+
</tab>
783
+
<tabtitle="Groovy"group-key="groovy">
784
+
785
+
```groovy
786
+
kotlin {
787
+
788
+
// Configure all compilations of all targets:
789
+
compilerOptions {
790
+
allWarningsAsErrors = true
791
+
}
792
+
}
793
+
```
794
+
795
+
</tab>
796
+
</tabs>
797
+
798
+
> The support for `compilerOptions {}` as a top-level block is [Experimental](components-stability.md#stability-levels-explained)
799
+
> and requires opt-in. It may be dropped or changed at any time. Use it only for evaluation purposes. We would appreciate
800
+
> your feedback on it in [YouTrack](https://kotl.in/issue).
801
+
>
802
+
{type="warning"}
803
+
804
+
752
805
## Dependencies
753
806
754
-
The `dependencies` block of the source set declaration contains the dependencies of this source set.
807
+
The `dependencies {}` block of the source set declaration contains the dependencies of this source set.
755
808
756
809
Learn more about [configuring dependencies](gradle-configure-project.md).
757
810
@@ -810,7 +863,7 @@ kotlin {
810
863
Additionally, source sets can depend on each other and form a hierarchy.
811
864
In this case, the [`dependsOn()`](#source-set-parameters) relation is used.
812
865
813
-
Source set dependencies can also be declared in the top-level `dependencies` block of the build script.
866
+
Source set dependencies can also be declared in the top-level `dependencies {}` block of the build script.
814
867
In this case, their declarations follow the pattern `<sourceSetName><DependencyKind>`, for example, `commonMainApi`.
815
868
816
869
<tabsgroup="build-script">
@@ -838,7 +891,7 @@ dependencies {
838
891
839
892
## Language settings
840
893
841
-
The `languageSettings` block of a source set defines certain aspects of project analysis and build. The following language settings are available:
894
+
The `languageSettings {}` block of a source set defines certain aspects of project analysis and build. The following language settings are available:
0 commit comments