0

I have two Android projects in my eclipse workspace.

The main project is called Hello and another android project which is used as a library reference is called HelloLibrary.

I have added the HelloLibrary project in eclipse build path by right clicking the Hello project and adding the HelloLibrary as a library project.

Eclipse manages to find, compile and build the Hello project that now uses the HelloLibrary code but on maven it cannot find the HelloLibrary project when i try to build and run my tests using:

mvn clean test -e

Full Stack trace is below:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile (default-testCompile) on project Hello: Compilation failure: Compilation failure:
[ERROR] /Users/Jonathan/Android work/Hello/src/test/java/com/example/hello/TestFullscreenActivity.java:[9,32] package com.example.hellolibrary does not exist
[ERROR] /Users/xxx/Android work/Hello/src/test/java/com/example/hello/TestFullscreenActivity.java:[30,17] cannot find symbol
[ERROR] symbol  : class Lib
[ERROR] location: class test.java.com.example.hello.TestFullscreenActivity
[ERROR] /Users/xxx/Android work/Hello/src/test/java/com/example/hello/TestFullscreenActivity.java:[30,31] cannot find symbol
[ERROR] symbol  : class Lib
[ERROR] location: class test.java.com.example.hello.TestFullscreenActivity
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile (default-testCompile) on project Hello: Compilation failure
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure
    at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:858)
    at org.apache.maven.plugin.compiler.TestCompilerMojo.execute(TestCompilerMojo.java:152)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
    ... 19 more

Any way i can add the HelloLibrary into maven build path or do i need to create a maven script artifact for the HelloLibrary as well?

Both are Android projects.

Edit. i added this to the Hello pom file

<dependency>
            <groupId>com.example.hellolibrary</groupId>
            <artifactId>HelloLibrary</artifactId>
            <version>1.0.0-SNAPSHOT</version>
            <type>apklib</type>
            <scope>compile</scope>
        </dependency>

and the Tests failed due to not finding the Lib class object located inside the HelloLibrary project

Here is my test class

/** * Test class */ @RunWith(RobolectricTestRunner.class) public class TestFullscreenActivity {

private String stringOne = "hello";
private String stringTwo = "world";

@Test
public void test() {

    Assert.assertEquals(true, false);

}

@Test
public void testTwo() {

    Lib lib = new Lib();
    Assert.assertEquals(stringOne+stringTwo, lib.combineText(stringOne, stringTwo));

}

@Test
public void testThree() {

    Assert.assertEquals(true, true);

}

}

And here is the Lib class located inside the HelloLibrary project

package com.example.hellolibrary;

/**
 * Test lib with some random methods
 * @author
 *
 */
public class Lib {

    public String combineText(String stringOne, String stringTwo){

        String result = "";

        result = stringOne + stringTwo;

        return result;

    }

}

Here is the top half of the pom file used for the HelloLibrary project

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example.hellolibrary</groupId>
    <artifactId>HelloLibrary</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>apklib</packaging>
    <name>HelloLibrary</name>

Thanks

Ricardo Gladwell
  • 3,770
  • 4
  • 38
  • 59
Jono
  • 17,341
  • 48
  • 135
  • 217

1 Answers1

1

There is a workaround to use non maven project in maven dependencies, we should not use it, but when we have not the choice, use the "system" scope:

<dependency>

  <groupId>org.yourjar</groupId>
  <artifactId>yourjar</artifactId>
  <version>0.1</version>
  <scope>system</scope>
  <systemPath>${project.basedir}/lib/yourjar.jar</systemPath>

</dependency> 
pdem
  • 3,880
  • 1
  • 24
  • 38
  • Cheers i will give this a go but when pushed live i will need to use proper maven dependencies – Jono Aug 27 '13 at 09:51
  • thanks.maybe that link gives a lot of tricks on maven dependencies: http://stackoverflow.com/questions/2065928/maven-2-assembly-with-dependencies-jar-under-scope-system-not-included – pdem Aug 27 '13 at 09:56
  • Did not seem to work. it cannot seem to find the reference class from the Library project. The artifact gets uploaded fine on the local .m3 repo but it fails to use its Class objects as it cannot locate it – Jono Aug 27 '13 at 10:53
  • Sorry this doesn't help. I was expecting that the following command line will make the project work as a maven project: mvn install:install-file -Dfile= \ -DgroupId= \ -DartifactId= \ -Dversion= \ -Dpackaging= \ -DlocalRepositoryPath= and then in your pom.xml include it with a classical scope compile – pdem Aug 27 '13 at 14:53
  • hi. i fixed the problem. the problem was with the library project. it did not include the src folder when it was built using maven. i had to move src/com.blah into src/main/java/com.blah and it containted the src folder. i then had to edit the build path in eclipse to point to src/main/java instead of src and that did the trick. i will mark your post as an answer as it provided me with the starting blocks needed to fix this issue. thanks – Jono Aug 27 '13 at 15:14