How to run custom Java under the classloader of a different Maven plugin

时间:2016-02-12 21:48:51

标签: android maven android-maven-plugin

I'm using android-maven-plugin to build and test an Android project. I need to set the ddmlib timeout using the workaround in message #15 here: https://code.google.com/p/android/issues/detail?id=104305

So I created a Maven module which sets the timeout, and I'm running it in my test project with

public static <T, R> R transform(final T t, final Function<T, R> rFromT, final R nullValue) {
    return
        t == null
            ? nullValue
            : rFromT.apply(t)
    ;
}

// which can be called like:
final Number x = getNumberThatCouldBeNull();
final long   y = transform(x, Number::longValue, 0L);

This successfully executes, and it does so before ddmlib queries the timeout for the problematic operation. The problem is that it is loaded by a different classloader than the android-maven-plugin, so android-maven-plugin (and thus ddmlib) can't see the change.

Is there any way to run the workaround using the same classloader that android-maven-plugin is running from?

0 个答案:

没有答案