akhikhl / gretty

Advanced gradle plugin for running web-apps on jetty and tomcat.
MIT License
655 stars 174 forks source link

java.lang.NoClassDefFoundError when dependencies with mulit level project #254

Open yjy8749 opened 8 years ago

yjy8749 commented 8 years ago

java.lang.NoClassDefFoundError: com/project/c/CClass

projectA:
AController.java
@RestController
public class AController {

    @RequestMapping(value = "/print",method = RequestMethod.GET)
    public String print(){
        new BClass().print();
        return this.getClass().getName();
    }
}

dependencies{

    compile "org.springframework.boot:spring-boot-starter-web"

    compile project(":projectB")

}

ProjectB:
public class BClass {
    public void print(){
        new CClass().print();
        System.out.println(this.getClass().getName());
    }
}
dependencies{
    compile project(":projectC")
}

ProjectC:
public class CClass {
    public void print(){
        System.out.println(this.getClass().getName());
    }
}

access : http://localhost:8080/print I got java.lang.NoClassDefFoundError: com/project/c/CClass

How can i do for this?thanks

yjy8749 commented 8 years ago

now i have a work around way to deal with,but it not so good.

def resolveCompile(sourceProject){
    sourceProject.buildFile.eachLine {
        line -> if(line.trim().startsWith("compile ")){
            if(line.indexOf("project")>=0){
                line = line.replace("'","\"")
                def p = project(line.substring(line.indexOf("\"")+1,line.lastIndexOf("\"")))
                project.dependencies.compile p
                resolveCompile(p)
            }else{
                if(line.indexOf("libs")>=0){
                    line = line.trim().substring(line.indexOf("libs.")+1);
                    line = libs[line]
                }else{
                    line = line.replace("'","\"")
                    line = line.substring(line.indexOf("\"")+1,line.lastIndexOf("\""));
                }
                if(line.indexOf("messaging")>=0){
                    println line
                }
                project.dependencies.compile line
            }
        }
    }
}

dependencies{

    resolveCompile(project)

}
akhikhl commented 8 years ago

Can you provide a complete, compilable example, allowing to reproduce the problem?

yjy8749 commented 8 years ago

@akhikhl Sorry For Late Reply,

example.zip

cd example gradle :a-project:appRun

then access : http://localhost:8080/print