Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In gradle how to use sources from relative path outside of project

I have following 2 projects placed adjacent to each other in some folder and I want to include specific sources from a non-gradle project into this project with the structure as follows.

rootfolder/
  my-gradle-project/
    src/main/java
    build.gradle

  my-non-gradle-project/
    src/main/java/com/example/utils

In build.gradle why would following not work ? What alternative do I have ?

Additionally I need to included specific java sources from the non-gradle project.

build.gradle

sourceSets.main.java.srcDirs = [
          'src/main/java', 
           '../my-non-gradle-project/src/main/java/com/example/util')]
like image 236
bhantol Avatar asked Dec 16 '16 18:12

bhantol


People also ask

What is subprojects in Gradle?

The subproject producer defines a task named buildInfo that generates a properties file containing build information e.g. the project version. You can then map the task provider to its output file and Gradle will automatically establish a task dependency.

How do I add a project as a dependency of another project Gradle?

To add a dependency to your project, specify a dependency configuration such as implementation in the dependencies block of your module's build.gradle file.

What is FileTree in Gradle?

A FileTree represents a hierarchy of files. It extends FileCollection to add hierarchy query and manipulation methods. You typically use a FileTree to represent files to copy or the contents of an archive. You can obtain a FileTree instance using Project.

What is runtimeClasspath in Gradle?

runtimeClasspath' contains the compiled classes of the source set, and task autowiring automatically adds the necessary task dependencies. Maybe you want 'sourceSets. main. compileClasspath'.


1 Answers

The following worked in intelliJ:

...
group 'org.example'
version '1.0-SNAPSHOT'

sourceSets {
    main {
        java{
            srcDirs '../my-non-gradle-project/src/main/java/com/example/util' /* include proto files from base project level */
        }
    }
}

sourceCompatibility = 1.11
...
like image 122
Dávid Tóth Avatar answered Oct 03 '22 12:10

Dávid Tóth