Add another java source directory to gradle script

前端 未结 4 836
温柔的废话
温柔的废话 2020-12-17 07:59

I hava an example java project package

package com.example.testing;

with such file tree

app
|
  src->com->example->testing->Main         


        
4条回答
  •  清酒与你
    2020-12-17 08:18

    The question is about "Adding"; the question of the text is describing a more concrete scenario. If one just wants to add an existing directory, this is the way to add:

    sourceSets.main.java.srcDirs += ['src/gen/java']
    

    An example full build.gradle is as follows:

    apply plugin: 'java'
    
    repositories {
        mavenCentral()
    }
    
    dependencies {
        implementation 'com.squareup:javapoet:1.12.1'
    }
    
    sourceSets.main.java.srcDirs += ['src/gen/java']
    

    JavaPoet s a Java API for generating .java source files. It is just used as example library for the build.gradle file.

提交回复
热议问题