问题描述:

Just moving my Android project over to Maven / Jenkins and am exploring the build / compile / testing procedures.

Issue:

I introduced a simple compilation error in the java code, but when i run mvn clean install package I get a build success. It's only when I deploy the App to my device that it crashes and fails.

Is there something wrong with my POM?

ps. I have XXXXX'd out some info. Don't worry about it.

 <?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>

<parent>

<groupId>xxxxx</groupId>

<artifactId>xxxxxx</artifactId>

<version>1.0.0</version>

</parent>

<groupId>xxxxx</groupId>

<artifactId>xxxx</artifactId>

<version>1.0.0</version>

<packaging>apk</packaging>

<name>Android App</name>

<dependencies>

<dependency>

<groupId>com.google.android</groupId>

<artifactId>android</artifactId>

<version>4.0.1.2</version>

<scope>provided</scope>

</dependency>

<dependency>

<groupId>com.actionbarsherlock</groupId>

<artifactId>library</artifactId>

<version>4.0.0</version>

<type>apklib</type>

</dependency>

</dependencies>

<build>

<plugins>

<plugin>

<groupId>com.jayway.maven.plugins.android.generation2</groupId>

<artifactId>android-maven-plugin</artifactId>

<configuration>

<androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile>

<assetsDirectory>${project.basedir}/assets</assetsDirectory>

<resourceDirectory>${project.basedir}/res</resourceDirectory>

<nativeLibrariesDirectory>${project.basedir}/src/main/native</nativeLibrariesDirectory>

<sdk>

<platform>15</platform>

<path>/Users/aidenfry/android-sdks</path>

</sdk>

<undeployBeforeDeploy>true</undeployBeforeDeploy>

</configuration>

<extensions>true</extensions>

</plugin>

<plugin>

<artifactId>maven-compiler-plugin</artifactId>

<configuration>

<source>1.5</source>

<target>1.5</target>

</configuration>

</plugin>

</plugins>

</build>

</project>

网友答案:

I suspect, that the reason you're not seeing an error is most likely because maven didn't even bother compiling your classes in the first place.

Maven has various conventions, and one of them is that it expects your sourcecode to be located under src/main/java.

I'm betting that you've just dropped the above pom.xml into your project root area and run mvn clean install. Maven will happily run that, but since you've probably left your source files in the default IDE locations, maven just skips over it. Have a look in your target directory and you'll see it hasn't compiled any classes in there for you

You have 2 options:

  1. Add this somewhere inside the <build> tags in the above pom : ${basedir}/src
  2. Re-arrange your source files so they follow the src/main/java structure.

Personally, I'd opt for number 2.

P.S, there is also src/main/test too, test classes should go there :)

You can read more about the configuration of the pom file here

相关阅读:
Top