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

Unable to initialize modules when run built fat jar #421

Closed
erickubenka opened this issue Apr 25, 2024 · 0 comments · Fixed by #422
Closed

Unable to initialize modules when run built fat jar #421

erickubenka opened this issue Apr 25, 2024 · 0 comments · Fixed by #422
Labels
bug Something isn't working

Comments

@erickubenka
Copy link
Contributor

Describe the bug
For an automation project that should continuously run a UI scraper, I decided to go for a public static void main function inside a Main class of my project. Then go for a gradle build including all dependencies to have a fat jar availbale to run the application standalone.
When executing the jar file the IoC kicks in when initializing Testerra, but somehow modules are tried to instantiated that are not part of the TesterraListener.DEFAULT_PACKAGES list ("eu.tsystems.mms.tic", "io.testerra") but still extends the com.google.inject.AbstractModule class.

To Reproduce
Steps to reproduce the behavior:

  1. Clone latest testerra-skeleton project
  2. Create a simple class Main in src/main/java (content shown below)
  3. Add a Gradle build step fo building a fat jar inside build.gradle (content shown below)
  4. Run gradle jar
  5. Run the built jar file cd builds/lib && java -jar testerra-skeletons-2-SNAPSHOT.jar

content of src/main/java/Main.java

import eu.tsystems.mms.tic.testframework.common.PropertyManagerProvider;
import eu.tsystems.mms.tic.testframework.testing.WebDriverManagerProvider;

public class Main implements WebDriverManagerProvider, PropertyManagerProvider {

    public static void main(String[] args) {
        System.out.println("Hello, World!");
        PROPERTY_MANAGER.setSystemProperty("tt.browser", "chrome");
        WEB_DRIVER_MANAGER.getWebDriver();
    }
}

content of build.gradle

jar {
    manifest {
        attributes 'Main-Class': 'Main'
        attributes 'Multi-Release': 'true'
    }

    from {
        configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
    }

    exclude("META-INF/*.SF", "META-INF/*.DSA", "META-INF/*.RSA", "guice-4.2.2-no_aop.jar")
    duplicatesStrategy = DuplicatesStrategy.WARN
}

Expected behavior
Application starts, Testerra boots successfully, WebDriverManager ensures that a browser will be opened.

Actual behavior

25.04.2024 08:54:59.231 [main][ERROR]: common.Testerra - Unable to initialize modules
java.lang.NoSuchMethodException: com.google.inject.util.Modules$OverrideModule.<init>()
        at java.lang.Class.getConstructor0(Class.java:3585) ~[?:?]
        at java.lang.Class.getConstructor(Class.java:2271) ~[?:?]
        at eu.tsystems.mms.tic.testframework.common.Testerra.initIoc(Testerra.java:182) ~[testerra-skeletons-2-SNAPSHOT.jar:?]
        at eu.tsystems.mms.tic.testframework.common.Testerra.<clinit>(Testerra.java:141) ~[testerra-skeletons-2-SNAPSHOT.jar:?]
        at eu.tsystems.mms.tic.testframework.testing.WebDriverManagerProvider.<clinit>(WebDriverManagerProvider.java:32) ~[testerra-skeletons-2-SNAPSHOT.jar:?]
        at Main.main(Main.java:7) ~[testerra-skeletons-2-SNAPSHOT.jar:?]
Exception in thread "main" java.lang.ExceptionInInitializerError
        at eu.tsystems.mms.tic.testframework.testing.WebDriverManagerProvider.<clinit>(WebDriverManagerProvider.java:32)
        at Main.main(Main.java:7)
Caused by: java.lang.NullPointerException: module cannot be null.
        at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:921)
        at com.google.inject.spi.ModuleSource.<init>(ModuleSource.java:70)
        at com.google.inject.spi.ModuleSource.<init>(ModuleSource.java:56)
        at com.google.inject.spi.Elements$RecordingBinder.getModuleSource(Elements.java:522)
        at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:330)
        at com.google.inject.spi.Elements.getElements(Elements.java:103)
        at com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:137)
        at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:103)
        at com.google.inject.Guice.createInjector(Guice.java:87)
        at com.google.inject.Guice.createInjector(Guice.java:69)
        at com.google.inject.Guice.createInjector(Guice.java:59)
        at eu.tsystems.mms.tic.testframework.common.Testerra.initIoc(Testerra.java:199)
        at eu.tsystems.mms.tic.testframework.common.Testerra.<clinit>(Testerra.java:141)
        ... 2 more

Screenshots
No screenshots applicable

Test
No test possible, due to run of the built fat jar.

Environment(please complete the following information):

  • OS: Debian 12
  • JDK: OpenJDK 17 and reproduced with OpenJDK 11
  • Gradle 7.6.4

Additional context
I will provide a pull request adressing this issue.

@erickubenka erickubenka added the bug Something isn't working label Apr 25, 2024
erickubenka added a commit to erickubenka/testerra that referenced this issue Apr 25, 2024
…ons of AbstractModule that does not fullfill package class will be instantiated.
martingrossmann added a commit that referenced this issue Apr 25, 2024
Fixes bug #421 - Run Testerra as part of fat jar standalone application
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant