WarSame
WarSame

Reputation: 1000

Gradle include compiled Java classes as a module dependency

I have been given a directory of compiled .class files in Java, which I must include as a dependency when building my JAR. I am building this JAR using Gradle. How do I include this directory as a dependency in Gradle?

Note: This is a directory that looks like 'com.example.projectname' with files like 'file1.class', 'file2.class', etc. I want these .class files to be in my JAR.

Upvotes: 2

Views: 3531

Answers (1)

Lukas Körfer
Lukas Körfer

Reputation: 14493

You can simply add any files to the JAR file of your project by configuring the respective jar task (created by the java plugin) :

jar {
    from files('path/to/file.class', 'path/to/otherfile.class'
    // or
    from fileTree('path/to/dir') {
        include '**/*.class'
    }
}

Please note, that those classes are part of the classpath when using the JAR, but they won't be available when using an IDE, as Gradle does not know these files in its own understanding of either source sets (for compilation) or configurations (for dependencies).

Upvotes: 2

Related Questions