Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9231871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:10:38+00:00 2026-06-18T06:10:38+00:00

So I have some classes in a module I wrote to help with Robolectric

  • 0

So I have some classes in a module I wrote to help with Robolectric style unit tests, and I want to be able to share this module in a bunch of my other modules. This module has unit tests of its own, and I have set it up as an apklib. I’m using the maven-android-plugin. The problem seems to be that it doesn’t recognize apklibs in the test scope. Are there any workarounds for this, or am I missing something?

One thing I’m noticing is if I run the command mvn install, everything builds and all my tests run fine, but if I do mvn test it says it can’t find classes.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T06:10:39+00:00Added an answer on June 18, 2026 at 6:10 am

    Maven has this concept of “the reactor”, which is just a fancy term for the list of projects being built. At the start of a Maven build, and at the end, Maven prints out this list of projects (using /project/name (XPath) if defined or groupId:artifactId otherwise).

    For each project in the reactor, Maven maintains a list of artifacts that have been attached. By default, each module’s pom.xml is attached, and as each plugin runs, they have the option of attaching additional artifacts. Most plugins do not attach artifacts, here are some plugins that do:

    • jar:jar creates a .jar and attaches it as the primary artifact (unless you specify a classifier in the configuration)
    • war:war creates a .war and attaches it
    • source:jar creates a .jar of the source Java code and attaches it with a classifier of source
    • javadoc:jar creates a .jar of the JavaDocs and attaches it with a classifier of javadoc
    • android:apklib creates a .apklib artifact and attaches it as the primary artifact

    There is also a default primary artifact (this is the one that gets replaced by jar:jar) which is actually a directory and not a file, as such it will not get installed or deployed to the local repository cache or a remote repository.

    So when in the reactor, and a plugin that attaches the primary artifact has not run yet (in your case android:apklib), and another plugin asks for the primary artifact, it will be given the directory ${project.build.outputDirectory}. If after the primary artifact as been attached, then that primary artifact will be provided.

    The test phase happens before the package phase, so will pass the the directory and not the .apklib.

    Things get more complex in a multi-module project (which is where my long intro should help you out)

    Maven has to build the test classpath. If one of the dependencies is within the reactor, Maven will use the artifact attached to the reactor. Otherwise it will use the local cache (populating from the remote repositories if necessary).

    When you run

    mvn test
    

    In a multimdule project from the root, there is no replacement of the default (directory-based) artifact, so intra-module classpath will be to the target/classes directories (and we are assuming that the android plugin knows how to handle such tests… you have found that it doesn’t).

    When you run

    mvn package
    

    or

    mvn install
    

    In the same project, however, because each module completes its life cycle sequentially, all the dependent modules will have swapped in their .apklib files as their attached artifact.

    Most likely the issue here is that your tests won’t work with a directory and need the actual .apklib file. in which case you have no choice but to push the lifecycle to at least the package phase.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some classes which extends a superclass, and in the JSP I want
I have some classes(call it Class A) which I would like to unit test
Let's say I have some classes like this: abstract class View(val writer: XMLStreamWriter) {
I have created some classes in a module, f.i. Request (app/models/api/request.rb) class Api::Request end
i have a maven module BaseProject with java classes in src/main/java . Some classes
For my current project I want to be able to load some classes from
I have some python modules containing mostly functions and a few classes. Each one
I have some classes that are used for Styling and all of them display
I have some classes that represent immutable objects (Quantity, Price, Probability). Is there some
I have some classes that, for one reason or another, cannot be or need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.