davidsusu / tree-printer

Java library for visualizing tree structures in the command line
Apache License 2.0
39 stars 8 forks source link

Fails to import tree printer module in JAVA Module based projects #6

Closed ShadowXBoss696 closed 2 years ago

ShadowXBoss696 commented 2 years ago

Hi Devs, While working on one of my projects, I decided to use your library to print out AST models on the console. But I met with a problem !!!

My project uses Java Module based structure (i.e., uses module-info.java file) as well as Gradle Build System. When I tried to import your library it says ...

error: module not found: tree.printer

My module-info.java file looks like this ...

module org.kodedevs.kode {
    requires info.picocli;
    requires org.fusesource.jansi;
    requires com.install4j.runtime;
    requires tree.printer;

    requires transitive java.scripting;

    opens org.kodedevs.kode.cli to info.picocli;

    provides javax.script.ScriptEngineFactory with
            org.kodedevs.kode.jsr223.KodeScriptEngineFactory;
}

If possible, can you add a module-info.java file to your project ...

With Regards, Edumate696

davidsusu commented 2 years ago

The problem is that the automatic module name tree.printer is not used by gradle (by default). A possible solution is to use some gradle plugin for explicitly generating the module:

buildscript {
    repositories {
        mavenCentral()
        gradlePluginPortal()
    }
    dependencies {
        classpath("de.jjohannes.gradle:extra-java-module-info:0.15")
    }
}

// ...

apply plugin: 'de.jjohannes.extra-java-module-info'

// ...

extraJavaModuleInfo {
    automaticModule('tree-printer-2.0.0.jar', 'tree.printer')
}

This is a java8 compatible project, so I can't add module-info.java without undesirable complications. However, in the next release, I will add Automatic-Module-Name: hu.webarticum.treeprinter to the manifest file.

ShadowXBoss696 commented 2 years ago

This is a java8 compatible project, so I can't add module-info.java without undesirable complications. However, in the next release, I will add Automatic-Module-Name: hu.webarticum.treeprinter to the manifest file.

Hi @davidsusu, I recognized the issue with module-info.java and Java8 compatibility and also recognized the workaround of using Automatic-Module-Name in the manifest file while experimenting with your project ... Finally I decided it's better to follow the workaround for my own project also, considering the different use cases available at this point ...

Thank You, for your quick reply on this matter ... Hope to work together someday 😊

With Regards, @Edumate696