mojohaus / servicedocgen-maven-plugin

ServicedocGen Maven Plugin
Apache License 2.0
2 stars 4 forks source link

Travis fails but local "mvn install" is successful #20

Closed hohwille closed 8 years ago

hohwille commented 8 years ago

https://travis-ci.org/mojohaus/servicedocgen-maven-plugin/jobs/96928943

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-invoker-plugin:2.0.0:verify (default) on project servicedocgen-maven-plugin: 1 build failed. See console output above for details. -> [Help 1]

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-invoker-plugin:2.0.0:verify (default) on project servicedocgen-maven-plugin: 1 build failed. See console output above for details.

    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)

    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:116)

    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)

    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)

    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:120)

    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:355)

    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155)

    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)

    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:216)

    at org.apache.maven.cli.MavenCli.main(MavenCli.java:160)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

    at java.lang.reflect.Method.invoke(Method.java:606)

    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)

    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)

    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)

    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)

Caused by: org.apache.maven.plugin.MojoFailureException: 1 build failed. See console output above for details.

    at org.apache.maven.plugin.invoker.InvokerSession.handleFailures(InvokerSession.java:258)

    at org.apache.maven.plugin.invoker.VerifyMojo.execute(VerifyMojo.java:137)

    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:132)

    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)

    ... 19 more
hohwille commented 8 years ago

As I can not see build.log in travis I am quite clueless. After all for travis it is a bad idea to report problems to external log files.

hohwille commented 8 years ago

Any chance to make maven invoker outout the build.log to the regular maven log? https://maven.apache.org/plugins/maven-invoker-plugin/run-mojo.html

Or any chance to get build.log from travis (directly or via configuring travis.yml)? https://docs.travis-ci.com/user/notifications/

mfriedenhagen commented 8 years ago

Did you try to set invoker.streamLogs to true? Then the output of invoker should be shown in the console.

mfriedenhagen commented 8 years ago

@hohwille, take a look at https://github.com/1and1/foss-parent/blob/master/pom.xml#L1072. The profile foss-parent-enable-invoker-log-output-on-travis will turn on invoker.streamLogs and invoker.showErrors when running in Travis.

hohwille commented 8 years ago

@mfriedenhagen thanks for the hint.

hohwille commented 8 years ago

So the actual error is this one:

Caused by: java.lang.ClassNotFoundException: org.codehaus.mojo.servicedocgen.it.jaxrs.json.simple.DemoRestService
[INFO]  at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
[INFO]  at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
[INFO]  at java.security.AccessController.doPrivileged(Native Method)
[INFO]  at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
[INFO]  at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
[INFO]  at java.lang.ClassLoader.loadClass(ClassLoader.java:358)

In other words the dynamic classloader behaves differently on the platform where travis runs than on my windows machine. I need to test on different machines as well. Maybe it does not work on windows in general. In this MOJO I am doing this (taken from hints for MOJO development on the web):

    @Parameter( defaultValue = "${project.runtimeClasspathElements}", readonly = true )
    private List<String> runtimeClasspathElements;

    private ClassLoader getProjectClassloader() throws MojoExecutionException {
        if ( this.projectClassloader == null ) {
            this.projectClassloader = new URLClassLoader( buildClasspathUrls(), this.getClass().getClassLoader() );
        }
        return this.projectClassloader;
    }

    private URL[] buildClasspathUrls() throws MojoExecutionException {
        List<URL> urls = new ArrayList<URL>( this.runtimeClasspathElements.size() );
        for ( String element : this.runtimeClasspathElements ) {
            try {
                urls.add( new File( element ).toURI().toURL() );
            } catch ( MalformedURLException e ) {
                throw new MojoExecutionException( "Unable to access project dependency: " + element, e );
            }
        }
        return urls.toArray( new URL[urls.size()] );
    }

Is there something wrong with this approach?

hohwille commented 8 years ago

Very strange. I added more debug output to the classloader setup and before the error I get this:

[INFO] [INFO] Generating "Service Documentation" report    --- servicedocgen-maven-plugin:1.0.0-beta-2-SNAPSHOT
[INFO] [DEBUG] Class matches: DemoRestService
[INFO] [INFO] Found service: DemoRestService
[INFO] [DEBUG] Adding to classloader: file:/home/travis/build/mojohaus/servicedocgen-maven-plugin/target/it/jaxrs-json-simple/target/classes
[INFO] [DEBUG] Adding to classloader: file:/home/travis/build/mojohaus/servicedocgen-maven-plugin/target/local-repo/javax/ws/rs/javax.ws.rs-api/2.0/javax.ws.rs-api-2.0.jar
[INFO] [DEBUG] Adding to classloader: file:/home/travis/build/mojohaus/servicedocgen-maven-plugin/target/local-repo/javax/validation/validation-api/1.1.0.Final/validation-api-1.1.0.Final.jar
[INFO] [INFO] Analyzing DemoRestService
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] BUILD FAILURE

So DemoRestService.java is found bout the DemoRestService.class is missing in classpath. What could be the reason for this error that can not be reproduced on my windows machine???

hohwille commented 8 years ago

Seems to be done in the same way also by other MOJOs:

Interesting to mention is that this also used to work in travis and failed exactly when the MOJO has been converted to a report.

mfriedenhagen commented 8 years ago

Just speculating: do you use the same Maven version? See mojo-parent .travis.yml for how to enforce specific Maven versions (default on Travis is 3.2.5 if I remember correctly).

mfriedenhagen commented 8 years ago

Just for the record:

Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T17:41:47+01:00)
Maven home: /usr/local/Cellar/maven/3.3.9/libexec
Java version: 1.7.0_80, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home/jre
Default locale: de_DE, platform encoding: UTF-8
OS name: "mac os x", version: "10.11.2", arch: "x86_64", family: "mac"
mfriedenhagen commented 8 years ago

When I change the following:

diff --git a/src/it/projects/jaxrs-json-simple/invoker.properties b/src/it/projects/jaxrs-json-simple/invoker.properties
index f0316ef..f18eaf7 100644
--- a/src/it/projects/jaxrs-json-simple/invoker.properties
+++ b/src/it/projects/jaxrs-json-simple/invoker.properties
@@ -1 +1 @@
-invoker.goals=site
\ No newline at end of file
+invoker.goals=verify site
\ No newline at end of file

it runs on my machine.

hohwille commented 8 years ago

OMG - stupid me! Indeed site does not triger compilation. It only worked on my machines as I once executed mvn install directly in src/it/projects/jaxrs-json-simple and theerfore the target folder was containing the compiled class files in src and these where copied to target/it/ so it worked.

I was really blind to find this one. @mfriedenhagen thank you so much :+1: you saved my day!