jeka-dev / jeka

Build and Run Java code for Everywhere
https://jeka.dev
Apache License 2.0
111 stars 15 forks source link

plugins not on build classpath? #47

Closed cuchaz closed 7 years ago

cuchaz commented 7 years ago

I'm trying to write a plugin for jerkar, but I'm having trouble using it in my build script. It appears that plugins are not added to the build classpath? Here's a minimial working example:

build script:

package test;

import org.jerkar.tool.builtins.javabuild.JkJavaBuild;

public class Build extends JkJavaBuild { 

    public void doTest() {
        System.out.println("plugin: " + org.jerkar.plugins.jacoco.JkBuildPluginJacoco.class);
    }
}

output for jerkar doTest:

 _______           _                 
(_______)         | |                
     _ _____  ____| |  _ _____  ____ 
 _  | | ___ |/ ___) |_/ |____ |/ ___)
| |_| | ____| |   |  _ (/ ___ | |    
 \___/|_____)_|   |_| \_)_____|_|
                                     The 100% Java build tool.

Jerkar Version : 0.4.5
Working Directory : /path/to/Test
Java Home : /usr/lib/jvm/java-8-openjdk-amd64/jre
Java Version : 1.8.0_111, Oracle Corporation
Jerkar Home : /path/to/jerkar-v0.4.5
Jerkar User Home : /path/to/.jerkar
Jerkar Repository Cache : /path/to/.jerkar/cache/repo
Jerkar Classpath : /path/to/jerkar-v0.4.5/libs/ext/*:/path/to/jerkar-v0.4.5/libs/builtins/org.jerkar.plugins-jacoco.jar:/path/to/jerkar-v0.4.5/libs/builtins/org.jerkar.plugins-sonar.jar:/path/to/jerkar-v0.4.5/org.jerkar.core.jar
Command Line : doTest
Specified System Properties : none.
Standard Options : buildClass=null, verbose=false, silent=false
Options : none.

----------------------------------------
Compiling build classes for project Test
----------------------------------------
|  Resolving compilation classpath ... 
|   \ Done in 0.005 seconds.
|  Compiling 1 source files using options : -d /path/to/Test/build/output/def-bin -cp /path/to/jerkar-v0.4.5/org.jerkar.core.jar ... 
/path/to/Test/build/def/test/Build.java:8: error: package org.jerkar.plugins.jacoco does not exist
        System.out.println("plugin: " + org.jerkar.plugins.jacoco.JkBuildPluginJacoco.class);
                                                                 ^
1 error
|   \ Done in 0.342 seconds.

java.lang.IllegalStateException: Compilation failed.
    at org.jerkar.api.java.JkJavaCompiler.compile(JkJavaCompiler.java:279)
    at org.jerkar.tool.Project.compileBuild(Project.java:225)
    at org.jerkar.tool.Project.compile(Project.java:89)
    at org.jerkar.tool.Project.compile(Project.java:72)
    at org.jerkar.tool.Project.execute(Project.java:121)
    at org.jerkar.tool.Main.main(Main.java:32)
 _______     _ _            _    _ 
(_______)   (_) |          | |  | |
 _____ _____ _| | _____  __| |  | |
|  ___|____ | | || ___ |/ _  |  |_|
| |   / ___ | | || ____( (_| |   _ 
|_|   \_____|_|\_)_____)\____|  |_|

                                   Total build time : 0.493 seconds.

I noticed the "Jerkar Classpath" section shows the plugins correctly, but the "Compiling 1 source files using options" -cp flag only lists the core jar.

How can I make sure the plugins are on the build classpath? Do I need to add something to my build script to tell jerkar to include the plugins? Or is this a bug?

djeang commented 7 years ago

Look like a bug indeed. Both Jacoco and Sonar plugin are bundled within Jerkar so normally it should run as is.

djeang commented 7 years ago

Looking further, it's a bug on unix script only (that explain why I didn't cacth it).

For windows CP is set "COMMAND="%JAVA_CMD%" %JERKAR_OPTS% -cp "%LOCAL_BUILD_DIR%%JERKAR_HOME%libs\ext\*;%JERKAR_HOME%org.jerkar.core-all.jar" org.jerkar.tool.Main %*"

For unix this is : -cp "$LOCAL_BUILD_DIR$JERKAR_HOME/libs/ext/*:$JERKAR_HOME/libs/builtins/*:$JERKAR_HOME/org.jerkar.core.jar" org.jerkar.tool.Main "$@" (line 161)

It should bereplace by something like -cp "$LOCAL_BUILD_DIR$JERKAR_HOME/libs/ext/*:$JERKAR_HOME/org.jerkar.core-all.jar" org.jerkar.tool.Main "$@"

As I don't have any easy way to run it on unixfor testing, please can you make the fix ?

cuchaz commented 7 years ago

Yeah, that definitely works, thanks! I'll send a PR with the fix.