Gradle multiple jars from single source folder

后端 未结 4 1264
执笔经年
执笔经年 2020-12-07 18:04

As for now we have a project structure with single source folder named src, which contains source code for three modules. What I want to do is:

1) Comp

4条回答
  •  情深已故
    2020-12-07 18:31

    We have the same problem at my company, ie. legacy code that is difficult to migrate into a "good" project structure, and the need to build several jars from the same codebase. We decided to define different sourceSets and build each of the sourceSets using standard Gradle.

    We then use iterators to add jar- and javadoc-tasks for each sourceSet:

    sourceSets.all { SourceSet sourceSet ->
        Task jarTask = tasks.create("jar" + sourceSet.name, Jar.class)
        jarTask.from(sourceSet.output)
        // Configure other jar task properties: group, description, manifest etc
    
        Task javadocTask = tasks.create("javadoc" + sourceSet.name, Javadoc.class)
        javadocTask.setClasspath(sourceSet.output + sourceSet.compileClasspath)
        javadocTask.setSource(sourceSet.allJava)
        // Extra config for the javadoc task: group, description etc
    
        Task javadocJarTask = tasks.create("javadocJar" + sourceSet.name, Jar.class)
        javadocJarTask.setClassifier("javadoc") // adds "-javadoc" to the name of the jar
        javadocJarTask.from(javadocTask.outputs)
        // Add extra config: group, description, manifest etc
    }
    

提交回复
热议问题