Skip to content

Commit efbcb77

Browse files
committed
[SHARED] Read API_BASE_URL from local gradle.properties
you can pass API_BASE_URL to gradle script for on CI e.g.
1 parent 41627a4 commit efbcb77

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ Multiplatform project and also to help someone just starting to explore KMP for
4848
* The iOS code can be modified or built by opening `iosApp/KmpShowcase.xcodeproj` in Xcode.
4949
* Running `./gradlew server:run` will deploy the server to localhost on port 8080.
5050

51+
Once you setup the project, you might want to change server address in your `~/.gradle/gradle.properties`:
52+
53+
```
54+
KMP_SHOWCASE_API_BASE_URL_DEFAULT=<insert> // default: http://localhost:9090
55+
KMP_SHOWCASE_API_BASE_URL_ANDROID=<insert> // default: http://10.0.2.2:9090
56+
KMP_SHOWCASE_API_BASE_URL_IOS=<insert> // default: http://127.0.0.1:9090
57+
```
58+
5159
## Contributions
5260

5361
If you've found an error in this sample, please file an issue.

shared/buildKonfig.gradle

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,21 @@ buildkonfig {
33

44
// default config is required
55
defaultConfigs {
6-
buildConfigField 'STRING', 'API_BASE_URL', 'http://localhost:9090'
6+
buildConfigField 'STRING', 'API_BASE_URL', getProperty('KMP_SHOWCASE_API_BASE_URL_DEFAULT', 'http://localhost:9090')
77
}
88

99
targetConfigs {
1010
android {
11-
buildConfigField 'STRING', 'API_BASE_URL', 'http://10.0.2.2:9090'
11+
buildConfigField 'STRING', 'API_BASE_URL', getProperty('KMP_SHOWCASE_API_BASE_URL_ANDROID', 'http://10.0.2.2:9090')
1212
}
1313

1414
ios {
15-
buildConfigField 'STRING', 'API_BASE_URL', 'http://127.0.0.1:9090'
15+
buildConfigField 'STRING', 'API_BASE_URL', getProperty('KMP_SHOWCASE_API_BASE_URL_IOS', 'http://127.0.0.1:9090')
1616
}
1717
}
18+
}
19+
20+
Object getProperty(String propertyName, Object defaultValue) {
21+
def propertyValue = project.properties[propertyName]
22+
return propertyValue != null ? propertyValue : defaultValue
1823
}

0 commit comments

Comments
 (0)