Robolectric downloading external maven dependencies at Runtime

1,979 views
Skip to first unread message

Abhi

unread,
Jun 11, 2013, 3:37:56 PM6/11/13
to robol...@googlegroups.com
I am new to Robolectric and trying to use this tool for my Unit testing. I downloaded Robolectric jar with all dependencies version 2.1 from Robolectric website and it works great locally but the only issue is it downloads some external dependencies from maven repository and our build environment doesn't allow access to any external repository. Is there any way I can get or create a jar which has all the dependency included even the ones Robolectric tries to download from Maven repo ? 


Downloading: org/robolectric/android-base/4.1.2_r1_rc/android-base-4.1.2_r1_rc.pom from repository central at http://repo1.maven.org/maven2
Transferring 1K from central
Downloading: org/sonatype/oss/oss-parent/7/oss-parent-7.pom from repository central at http://repo1.maven.org/maven2
Transferring 5K from central
Downloading: org/robolectric/android-kxml2/4.1.2_r1_rc/android-kxml2-4.1.2_r1_rc.pom from repository central at http://repo1.maven.org/maven2
Transferring 1K from central
Downloading: org/robolectric/android-luni/4.1.2_r1_rc/android-luni-4.1.2_r1_rc.pom from repository central at http://repo1.maven.org/maven2
Transferring 1K from central
Downloading: org/json/json/20080701/json-20080701.pom from repository central at http://repo1.maven.org/maven2
Transferring 2K from central
Downloading: org/ccil/cowan/tagsoup/tagsoup/1.2/tagsoup-1.2.pom from repository central at http://repo1.maven.org/maven2
Transferring 1K from central
Downloading: org/ccil/cowan/tagsoup/tagsoup/1.2/tagsoup-1.2.jar from repository central at http://repo1.maven.org/maven2
Downloading: org/robolectric/android-base/4.1.2_r1_rc/android-base-4.1.2_r1_rc-real.jar from repository central at http://repo1.maven.org/maven2
Downloading: org/json/json/20080701/json-20080701.jar from repository central at http://repo1.maven.org/maven2
Transferring 9901K from central
Transferring 37K from central
Transferring 88K from central
Downloading: org/robolectric/android-kxml2/4.1.2_r1_rc/android-kxml2-4.1.2_r1_rc-real.jar from repository central at http://repo1.maven.org/maven2
Transferring 43K from central
Downloading: org/robolectric/android-luni/4.1.2_r1_rc/android-luni-4.1.2_r1_rc-real.jar from repository central at http://repo1.maven.org/maven2
Transferring 44K from central
WARNING: no system properties value for ro.build.date.utc
Downloading: org/robolectric/android-res/4.1.2_r1_rc/android-res-4.1.2_r1_rc.pom from repository central at http://repo1.maven.org/maven2
Transferring 1K from central
Downloading: org/robolectric/android-res/4.1.2_r1_rc/android-res-4.1.2_r1_rc-real.jar from repository central at http://repo1.maven.org/maven2
Transferring 14149K from central

Thanks
Abhi

Phil Goodwin

unread,
Jun 11, 2013, 4:34:10 PM6/11/13
to robol...@googlegroups.com

You could build a project that uses Robolectric on a machine that can access a remote repo and then transfer the artifacts from that machines local Maven repo to the local Maven repo on the machine that hosts your project. Be sure both projects use the same version of Android as that will affect which artifacts Robolectric looks for.

--
You received this message because you are subscribed to the Google Groups "Robolectric" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robolectric...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Abhi

unread,
Jun 11, 2013, 5:47:21 PM6/11/13
to robol...@googlegroups.com
Thanks for the reply Phil. The problem is we can't create a .m2 directory on build machine to put these artifacts. That's why I was hoping if there is any jar with all the dependencies in it (even the ones Robolectric downloads from external repo). Please let me know if I can make some code changes in Robolectric which will not download any dependency. I can manually add the dependencies to the class path (Android.mk). 

Abhi   

Abhi

unread,
Jun 11, 2013, 6:36:12 PM6/11/13
to robol...@googlegroups.com
Just want to clarify that when I say "I can manually add the dependencies to the class path (Android.mk)" I meant adding the dependencies which Robolectric tries to download from Maven repo. (As mentioned in the logs above). I can still use all the other dependency provided by Robolectric dependency jar. 

Thanks
Abhinav 

Eliram Aharon

unread,
Jul 4, 2013, 8:01:04 AM7/4/13
to robol...@googlegroups.com
Hi did U find any solution, for working offline?

Bademus l.

unread,
Dec 2, 2014, 10:15:49 AM12/2/14
to robol...@googlegroups.com
It is absolute nonsens that robolectric tries to download smth by itself....
Is it possible to declare all needed dependencies for robolectric2.4 with gradle?

Erich Douglass

unread,
Dec 2, 2014, 12:37:42 PM12/2/14
to robol...@googlegroups.com
If you were a little more polite, we might actually try and help you.

Bademus l.

unread,
Dec 2, 2014, 3:50:26 PM12/2/14
to robol...@googlegroups.com
It's a bad start, little more politeness: sorry

Actually found via codegrep robolectric.offline and robolectric.dependency.dir

Is there any roboelectric package with all build in deps (jar-with-dependencies tries to download smth)?

I'm actually looking for the flawless to integrate it into gradle and AS without any unexpected and uncontrolled dependencies.

Here the working concept of AS integration https://github.com/bademux/robolectric-java-gradle-plugin

Thanks.

P.S. download dependencies on start - wtf :)

Erich Douglass

unread,
Dec 2, 2014, 3:55:33 PM12/2/14
to robol...@googlegroups.com
Robolectric downloads a version of Android at runtime that's built
specifically for running tests. Each API level is ~40mb, so producing
a single jar file that includes everything would be prohibitive. All
of the artifacts are available on maven central under the coordinates:
org.robolectric:android-all. You can grab the API levels from maven
central and use them with offline mode.
> For more options, visit https://groups.google.com/d/optout.

Bademus l.

unread,
Dec 2, 2014, 4:41:43 PM12/2/14
to robol...@googlegroups.com
ah. so this is what is  about those 4.3_r2-robolectric-0
I'm thinking about passing responsibility for downloading Robolelectric Android Runtime to gradle, ex.
roboelectric{
   useWithTestAndroidRuntime('4.3_r2')
}

1. Gradle will place artifacts to classpath is it sounds OK for you?
2. How to force gradle to find Robolelectric Android Runtime on classpath (runtime dependency)?

3. Is roboelectric-jar-with-dependencies+RobolelectricAndroidRuntime the only combo I need in runtime?

Thanks in advance. It was a little bit stupid to start conversation with offense, but totally unexpected behavior eats 3 hours of my life...

Erich Douglass

unread,
Dec 3, 2014, 1:27:51 PM12/3/14
to robol...@googlegroups.com
Robolectric uses a custom ClassLoader, so having those jars on the classpath won't help. If you don't use the offline property, it will try to go to maven central to resolve the artifacts it needs. Your best bet is to download all the android-all jars and put them in a directory, then use the offline properties to tell Robolectric where those jars are located.

Bademus

unread,
Dec 3, 2014, 2:46:34 PM12/3/14
to robol...@googlegroups.com

I implemented it as custom ClasspathDependencyLocator used by custom RobolectricTestRunner .


Any chance to push changes in upstream?


Unfortunately I don't know how to pass system.properties from AndroidStudio launcher to test runner with zero-conf, so
generated_org.robolectric.Config.properties is produced by my plugin and used later by IdeAwareRobolectricTestRunner.
Actually the main blocker for single org.robolectric.Config.properties on classpath is relative nature of android.assets\resources\manifest properties (are prepended by './').
I'd like to implement it in a way acceptable for robolectric team team.

Please contact me personally or let's discuss it in https://groups.google.com/forum/#!topic/robolectric/Eg1drYGSMAs .

P.S. testing (including configuration process) should be painless as much as possible.
Thanks.
Bademus

Erich Douglass

unread,
Dec 3, 2014, 3:39:20 PM12/3/14
to robol...@googlegroups.com
Push the test runner upstream? It's specific to your gradle plugin, so it's not really appropriate for robolectric core.

--

Bademus

unread,
Dec 3, 2014, 4:04:46 PM12/3/14
to robol...@googlegroups.com
Nope.
I need "interface" to integrate it with IDE.
  1. ClasspathDependencyLocator, to read Robolectric Android Dependency from string formatted as classpath string (formattes as <path> ant\maven\gradle standard)
  2. Read robolectric.dependency.cache (reuse dependency.dir with some prefix like classpath:// ??)  from org.robolectric.Config.properties 
  3. Read path to manifest\res\assets as absolute path from org.robolectric.Config.properties (located on test runtime classpath)
So as you see, changes I indenting to add are pretty standard and used wide in java world.
The code shared by me is POC. I can adapt it on your wish.

--
You received this message because you are subscribed to a topic in the Google Groups "Robolectric" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/robolectric/nJgHtdbkpi8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to robolectric...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages