Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add module-info.java file #25

Merged
merged 9 commits into from
Dec 18, 2023
Merged

Add module-info.java file #25

merged 9 commits into from
Dec 18, 2023

Conversation

Dylan700
Copy link
Contributor

@Dylan700 Dylan700 commented Jul 31, 2023

Following #24, I have added a module-info.java file to the repository to modularize this project.

Unfortunately, 2 template engine libraries cannot be included since they are not modularized themselves, and do not contain automatic-module-name entries:

  1. StringTemplate4
  2. Velocity

However, this particular issue should only affect others using this project if they are using the java module system (non-modular projects using this dependency should be fine).

Furthermore, while this code does successfully compile with mvn package, I am receiving errors with the tests.

[ERROR] /usr/src/mymaven/src/test/java/io/javalin/jte/PrecompileJteTestClasses.java:[17,55] cannot access gg.jte.CodeResolver
[ERROR] class file for gg.jte.CodeResolver not found

I can successfully generate a .jar file with the module information by running mvn package -Dmaven.test.skip, however, this is not a good solution to that problem.

@tipsy
Copy link
Member

tipsy commented Jul 31, 2023

Unfortunately I'm not very experience with modules, but you can see what was done by @SentryMan for the main artifact:

@Dylan700
Copy link
Contributor Author

Dylan700 commented Aug 1, 2023

Thanks for the info, I've figured it out. Everything seems to be working fine on my end now.

@Dylan700 Dylan700 marked this pull request as ready for review August 1, 2023 01:28
@tipsy
Copy link
Member

tipsy commented Aug 1, 2023

Thanks for the info, I've figured it out. Everything seems to be working fine on my end now.

Great! Could you also add this at build time? (second PR I linked)

@Dylan700
Copy link
Contributor Author

Dylan700 commented Aug 1, 2023

Great! Could you also add this at build time? (second PR I linked)

Sure, although are you sure this is necessary? When you say build time, do you mean generating/compiling the jar with mvn package?

The reason I ask is because I have currently imported the generated jar and checked the module info with jar --file=thejar.jar --describe-module and it's working in my current modular project.

Let me know what you think.

@tipsy
Copy link
Member

tipsy commented Aug 2, 2023

Sure, although are you sure this is necessary? When you say build time, do you mean generating/compiling the jar with mvn package?

The project breaks in IntelliJ, so this is unfortunately required (see javalin/javalin#1922)

@tipsy
Copy link
Member

tipsy commented Aug 2, 2023

I have not actually tested this one though, but I assume it's going to be the same. If you can confirm that tests can still be run from IntelliJ, then this is not needed :)

@Dylan700
Copy link
Contributor Author

Dylan700 commented Aug 2, 2023

I have not actually tested this one though, but I assume it's going to be the same. If you can confirm that tests can still be run from IntelliJ, then this is not needed :)

Oh ok that makes sense, thanks. I do not usually use IntelliJ but I'll confirm this and get back to you when I get the chance.

@tipsy
Copy link
Member

tipsy commented Aug 26, 2023

Are you testing it in intellij now? 😊

@Dylan700
Copy link
Contributor Author

Hey @tipsy,

Yep, currently trying to sort this out 😆

When I add the moditech package as per the second PR linked, I receive this error:
Screen Shot 2023-08-28 at 5 17 23 pm

It seems that particular plugin is not needed in our case?

Running the tests through a JUnit configuration in IntelliJ returns an error, however, setting up a configuration for maven works perfectly.
Screen Shot 2023-08-28 at 5 17 52 pm

Screen Shot 2023-08-28 at 5 19 30 pm

@tipsy
Copy link
Member

tipsy commented Sep 9, 2023

Running the tests through a JUnit configuration in IntelliJ returns an error, however, setting up a configuration for maven works perfectly.

Yeah, this is what we are trying to avoid by including it during build. Could you include the plugin?

@Dylan700
Copy link
Contributor Author

Hi @tipsy,

I've added the moditech plugin. Since you're more familiar with the project, could you please check if this is working on your end before merging?

@tipsy
Copy link
Member

tipsy commented Nov 27, 2023

Thanks @Dylan700 ! You will also need to move the module-info to the root:

/src/main/java/module-info.java/module-info.java

@Dylan700
Copy link
Contributor Author

No worries at all @tipsy. I've just made that change, let me know if there's anything else.

@tipsy
Copy link
Member

tipsy commented Nov 27, 2023

Looks great, thank you!

@tipsy
Copy link
Member

tipsy commented Nov 27, 2023

Looks great, thank you!

Shows how much I know... !

All builds are failing with this error now:

Error:  Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.10.1:testCompile (java-test-compile) on project javalin-rendering: Execution java-test-compile of goal org.apache.maven.plugins:maven-compiler-plugin:3.10.1:testCompile failed: Can't compile test sources when main sources are missing a module descriptor -> [Help 1]
Error:  
Error:  To see the full stack trace of the errors, re-run Maven with the -e switch.
Error:  Re-run Maven using the -X switch to enable full debug logging.
Error:  
Error:  For more information about the errors and possible solutions, please read the following articles:
Error:  [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
Error: Process completed with exit code 1.

@Dylan700
Copy link
Contributor Author

Dylan700 commented Nov 27, 2023

Ah dang, what was the command you used for that? I'm not sure how maven works exactly, but I know that for gradle, the module-info.java file needs to be in the src folder.

If you go back to commit 0117ced, do you get the same error? That commit works for me when running mvn clean test.

@tipsy
Copy link
Member

tipsy commented Dec 3, 2023

I'll try later today!

@tipsy
Copy link
Member

tipsy commented Dec 3, 2023

I have no idea what's going on here @Dylan700 - @SentryMan can you see what's wrong?

@Dylan700
Copy link
Contributor Author

Dylan700 commented Dec 3, 2023

Yeah, from my experience, IntelliJ is very temperamental. It definitely works via the command line in the previous commits, but not through IntelliJ. Hopefully SentryMan can help us out!

@SentryMan
Copy link

SentryMan commented Dec 12, 2023

try adding <useModulePath>false</useModulePath> to surefire maven plugin configuration.

@Dylan700
Copy link
Contributor Author

Dylan700 commented Dec 12, 2023

Thank @SentryMan, upon adding the suggested configuration, I realised that maybe the test class needs its own module.info file. This new commit currently works with mvn test but I'll need @tipsy or yourself to confirm in IntelliJ (haven't got it installed right now).

@Dylan700
Copy link
Contributor Author

Dylan700 commented Dec 13, 2023

Just removed the moditech plugin, the workflow checks should pass now. Might be worth adding another check for using this in a modular project too to ensure it definitely works. Will also need someone to check it works on IntelliJ

@tipsy
Copy link
Member

tipsy commented Dec 14, 2023

Without the plugin I think we would unfortunately be back at square one :/

I'll check it out locally to confirm.

Edit: Yes, not working in IntelliJ without the plugin.

@tipsy
Copy link
Member

tipsy commented Dec 14, 2023

@Dylan700 I moved the module-info.java file to meta/module-info.java, and updated the plugin config:

<plugin>
    <groupId>org.moditect</groupId>
    <artifactId>moditect-maven-plugin</artifactId>
    <version>1.0.0.Final</version>
    <executions>
        <execution>
            <id>add-module-infos</id>
            <phase>package</phase>
            <goals>
                <goal>add-module-info</goal>
            </goals>
            <configuration>
                <overwriteExistingFiles>true</overwriteExistingFiles>
                <module>
                    <moduleInfoFile>./meta/module-info.java</moduleInfoFile>
                </module>
            </configuration>
        </execution>
    </executions>
</plugin>

@tipsy
Copy link
Member

tipsy commented Dec 14, 2023

Don't ask me why this works, but it does... 😓

@Dylan700
Copy link
Contributor Author

@tipsy, awesome thanks heaps for confirming, haha as long as it's working I'm happy 😂

Did you put it into a commit?

@tipsy
Copy link
Member

tipsy commented Dec 15, 2023

Did you put it into a commit?

No, you can have that honor 😄

@Dylan700
Copy link
Contributor Author

Haha ok, just added it back. Although the command mvn package doesn't seem to work now. Let me know how it looks on your end in IntelliJ. Not sure if I need to also move the module-info.java in both src and main folders or not.

@tipsy
Copy link
Member

tipsy commented Dec 15, 2023

Let me know how it looks on your end in IntelliJ. Not sure if I need to also move the module-info.java in both src and main folders or not.

Not seeing any commit yet 😄

@Dylan700
Copy link
Contributor Author

Dylan700 commented Dec 15, 2023

Not seeing any commit yet 😄

There we go 😆

@tipsy
Copy link
Member

tipsy commented Dec 15, 2023

Still need to move the module-info.java file to meta/module-info.java. I think you can delete the one from the test folder.

@Dylan700
Copy link
Contributor Author

@tipsy, done

@tipsy
Copy link
Member

tipsy commented Dec 18, 2023

🤞

@tipsy
Copy link
Member

tipsy commented Dec 18, 2023

Thanks @Dylan700 , looks like it went through!

@tipsy tipsy merged commit 9f896a0 into javalin:main Dec 18, 2023
6 checks passed
@Dylan700
Copy link
Contributor Author

Awesome, thanks for your assistance with this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants