j2objc-contrib / j2objc-gradle

This plugin is no longer actively maintained. J2ObjC Gradle Plugin: enables Java source to be part of an iOS application's build so you can write an app's non-UI code (such as application logic and data models) in Java, which is then shared by Android apps (natively Java) and iOS apps (using J2ObjC), all as part of your usual Android Gradle build.
https://github.com/j2objc-contrib/j2objc-gradle
Apache License 2.0
139 stars 43 forks source link

Possible to add *junit* to *spec.libraries* in generated podspec? #600

Open adil-hussain-84 opened 8 years ago

adil-hussain-84 commented 8 years ago

I have a TestContracts Java module in my project that has classes which have JUnit / Hamcrest assertions. I'd like to translate these classes and use them in the tests target of my iOS module. The build.gradle file of my TestContracts module is as follows:

plugins {
    id 'java'
    id 'com.github.j2objccontrib.j2objcgradle' version '0.6.0-alpha'
}

dependencies {
    compile project(':SharedCode')
    compile 'junit:junit:4.12' // this is compile scope deliberately
    compile 'org.hamcrest:hamcrest-core:1.3' // this is compile scope deliberately
}

j2objcConfig {
    autoConfigureDeps true
    minVersionIos '8.4'
    supportedArchs += ['ios_i386']
    translateArgs '--no-package-directories'
    translateArgs '--prefixes', 'prefixes.properties'
    xcodeProjectDir '../iOS'
    xcodeTargetsIos 'RetailSDKTests'
    finalConfigure()
}

The Java to Objective-C translation step of the Gradle build completes but the :iOS:xcodebuild step fails with a linking error. It can't make sense of the JUnit assertions. The problem I've discovered is that the 'junit' library is missing from the podspec files created in the TestContracts/build/j2objcOutputs folder.

So question is: is it possible specify the JUnit and Hamcrest dependencies in a way that they're included in the generated podspec file? And, if so, how?

adil-hussain-84 commented 8 years ago

I've updated the description of the issue above as I've discovered the root of the problem... but still don't know how to solve the issue so I haven't closed it yet. The best I've come up with right now is to add the following in the "Other linker flags" in Xcode for my tests target:

$(inherited)
-l"junit"

Would be great if I could do this via the build.gradle file instead of hard-coding in my Xcode project.