Hi, In order to configure my build I need to expo...
# announcements
g
Hi, In order to configure my build I need to expose some private methods from a 3rd party plugin. Can I do that using Kotlin extensions? The plugin in question is the
xcode-compat
, and the method that I’d like to expose is
setupTask
(which is available here: https://github.com/Kotlin/xcode-compat/blob/6633fe0696c38c9eee2f789164b8b945910fdc13/xcode-compat/src/main/kotlin/org/jetbrains/kotlin/xcodecompat/XcodeCompatPlugin.kt#L27) Please also note that this method will depend on other private ones. I tested copying and pasting the plugin locally and then applying it, it works after that, but I don’t know if I can do that without forking the plugin. Can we?
g
extensions are syntactic sugar over static functions, so they don't violate visibility
g
Instead of changing the visibility, do you think it is possible to create a new method inside of that scope, which will change the behavior? What I different there is that we have a class and the class have private methods wich are extending another one from inside. If I can create a setupCustomTask I think this could solve the problem to me. But this method will need to use the methods defined inside of that class
g
You can't access private functions
extensions are just static calls
e.g.
fun Abc.extension()
is the same as
fun extension(abc: Abc)
g
For my case I was able to find a workaround, not really changing the function visibility but creating two extensions:
Copy code
fun KotlinXcodeExtension.setupFramework(kotlinNativeTarget: KotlinNativeTarget?) {
}

fun KotlinXcodeExtension.setupTask(nativeBinary: NativeBinary) {
	val `class` = KotlinXcodeExtension::class.java
	val method = `class`.getDeclaredMethod("setupTask", NativeBinary::class.java)
	method.setAccessible(true)
	method.invoke(this, nativeBinary)
}
so I can use something like
Copy code
xcode {
		setupFramework (
			iosX64("myApp") {
				binaries {
					framework {
						baseName = "myFramework"
						setupTask(this)
					}
				}
			}
		)
	}
The usual way to use this plugin is like:
Copy code
xcode {
		setupFramework (
			binaries {
				framework {
					baseName = "myFramework"
				}
			}
		)
	}