Giter Club home page Giter Club logo

Comments (17)

racc avatar racc commented on August 22, 2024

Is it possible to exclude a specific transitive dependency?
http://www.scala-sbt.org/0.13/docs/Library-Management.html#Exclude+Transitive+Dependencies

from typesafeconfig-guice.

racc avatar racc commented on August 22, 2024

See also - https://github.com/sbt/sbt-assembly#exclude-specific-transitive-deps.

from typesafeconfig-guice.

fayimora avatar fayimora commented on August 22, 2024

@racc Yes I tried to. It fixed the duplication errors and left me with this runtime issue

com.google.inject.ConfigurationException: Guice configuration errors:

1) No implementation for java.lang.String annotated with @com.github.racc.tscg.TypesafeConfig(value=db.driver) was bound.
  while locating java.lang.String annotated with @com.github.racc.tscg.TypesafeConfig(value=db.driver)
    for parameter 0 at com.brutehack.services.UsersService.<init>(UsersService.scala:19)
  while locating com.brutehack.services.UsersService
    for parameter 1 at com.brutehack.controllers.UsersController.<init>(UsersController.scala:14)
  while locating com.brutehack.controllers.UsersController

2) No implementation for java.lang.String annotated with @com.github.racc.tscg.TypesafeConfig(value=db.password) was bound.
  while locating java.lang.String annotated with @com.github.racc.tscg.TypesafeConfig(value=db.password)
    for parameter 3 at com.brutehack.services.UsersService.<init>(UsersService.scala:19)
  while locating com.brutehack.services.UsersService
    for parameter 1 at com.brutehack.controllers.UsersController.<init>(UsersController.scala:14)
  while locating com.brutehack.controllers.UsersController

3) No implementation for java.lang.String annotated with @com.github.racc.tscg.TypesafeConfig(value=db.url) was bound.
  while locating java.lang.String annotated with @com.github.racc.tscg.TypesafeConfig(value=db.url)
    for parameter 1 at com.brutehack.services.UsersService.<init>(UsersService.scala:19)
  while locating com.brutehack.services.UsersService
    for parameter 1 at com.brutehack.controllers.UsersController.<init>(UsersController.scala:14)
  while locating com.brutehack.controllers.UsersController

4) No implementation for java.lang.String annotated with @com.github.racc.tscg.TypesafeConfig(value=db.user) was bound.
  while locating java.lang.String annotated with @com.github.racc.tscg.TypesafeConfig(value=db.user)
    for parameter 2 at com.brutehack.services.UsersService.<init>(UsersService.scala:19)
  while locating com.brutehack.services.UsersService
    for parameter 1 at com.brutehack.controllers.UsersController.<init>(UsersController.scala:14)
  while locating com.brutehack.controllers.UsersController

4 errors
    at com.google.inject.internal.InjectorImpl.getProvider(InjectorImpl.java:1042)
    at com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1047)
    at com.twitter.inject.Injector.instance(Injector.scala:12)
    at com.twitter.finatra.http.routing.HttpRouter.add(HttpRouter.scala:89)
    at com.brutehack.ApplicationServer.configureHttp(ApplicationServer.scala:23)
    at com.twitter.finatra.http.HttpServer$class.postStartup(HttpServer.scala:37)
    at com.brutehack.ApplicationServer.postStartup(ApplicationServer.scala:14)
    at com.twitter.inject.app.App$class.main(App.scala:45)
    at com.brutehack.ApplicationServer.com$twitter$inject$server$TwitterServer$$super$main(ApplicationServer.scala:14)
    at com.twitter.inject.server.TwitterServer$class.main(TwitterServer.scala:40)
    at com.brutehack.ApplicationServer.main(ApplicationServer.scala:14)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.twitter.app.App$$anonfun$nonExitingMain$3.apply(App.scala:168)
    at com.twitter.app.App$$anonfun$nonExitingMain$3.apply(App.scala:167)
    at scala.Option.foreach(Option.scala:257)
    at com.twitter.app.App$class.nonExitingMain(App.scala:167)
    at com.brutehack.ApplicationServer.nonExitingMain(ApplicationServer.scala:14)
    at com.twitter.app.App$class.main(App.scala:133)
    at com.brutehack.ApplicationServer.main(ApplicationServer.scala:14)
    at com.brutehack.ApplicationServerMain.main(ApplicationServer.scala)
Exception thrown in main on startup

from typesafeconfig-guice.

racc avatar racc commented on August 22, 2024

@fayimora How did you exclude the transitive dependency? Did you exclude guice:4.0 from finatra or guice:4.0:no_aop from typesafeconfig-guice?

from typesafeconfig-guice.

fayimora avatar fayimora commented on August 22, 2024

@i tried excluding guice from both like this:

"com.twitter.finatra" %% "finatra-http" % versions.finatra,// exclude("com.google.inject", "guice"),
"com.github.racc" % "typesafeconfig-guice" % "0.0.2" exclude("com.google.inject", "guice"),

from typesafeconfig-guice.

racc avatar racc commented on August 22, 2024

Maybe some other things to try would be to exclude the actual guice-no-aop jar file, or maybe the individual conflicting class files?
If all else fails I guess you could fork the project and specify a different guice dependency in the build?

I don't know why the runtime issue occurs when you exclude the transitive dependency - you would need to do some debugging to ensure that the parameters are getting bound within the TypesafeConfigModule. I take it that it only occurs at runtime when you've built the final Fat Jar assembly?

from typesafeconfig-guice.

fayimora avatar fayimora commented on August 22, 2024

Yes it only occurs at runtime. I was a bit surprised too that excluding guice didn't do the trick.

To build the lib with a different dependency, can I just change the guice dependency in build.gradle and and run gradle build or is there a custom build command.

from typesafeconfig-guice.

racc avatar racc commented on August 22, 2024

Yes just change the guice dependency in the build.gradle.
gradle build will get you a built jar.

from typesafeconfig-guice.

fayimora avatar fayimora commented on August 22, 2024

@racc I built the lib using:

dependencies {
    compile 'com.typesafe:config:1.3.0'
    compile 'org.reflections:reflections:0.9.10'
    compile 'com.google.inject:guice:4.0'

    testCompile 'junit:junit:4.12'
}

Output was:
screenshot 2016-01-13 10 57 20

I still got a jar so i used it in my project but that didn't solve the problem 😭

from typesafeconfig-guice.

racc avatar racc commented on August 22, 2024

@fayimora I would run the build without signArchives task, try:
gradle build -x signArchives

from typesafeconfig-guice.

fayimora avatar fayimora commented on August 22, 2024

@racc Yes I did that, also had to add reflections explicitly to my build.sbt but still no progress.

Incase you want to reproduce the problem, my test bed is here.

If you clone that and sbt run, the server will startup fine. However, if you package with sbt assembly and run the packaged jar using:

java -jar -Dconfig.file=src/main/resources/conf/development.conf target/scala-2.11/brutehack.jar

...you get the Guice config errors.

from typesafeconfig-guice.

racc avatar racc commented on August 22, 2024

Are you sure that the config file is being picked up by the program - maybe you could print out the contents of the config to the terminal after it is parsed?

Also, what is the contents of brutehack.jar? Have you confirmed that the assembly plugin is creating the expected package jar?

from typesafeconfig-guice.

racc avatar racc commented on August 22, 2024

The only other thing I can think of is that the classpath scanning isn't working - TypesafeConfigModule scans your classpath to find injection parameters annotated with the TypesafeConfig annotation. Not sure why it wouldn't be working though...

from typesafeconfig-guice.

fayimora avatar fayimora commented on August 22, 2024

@racc Yes the config file is certainly being picked up. After loading the file, it prints a value from it. From all indications, the jar file is fine as I never had problems with it before I added config and typesafe-config.

Would this warning have anything to do with that scan?

09:17:33.110 [main] WARN  org.reflections.Reflections - given scan urls are empty. set urls in the configuration

When running directly(no jar), it looks like this:

[info] 09:16:36.176 [main] DEBUG org.reflections.Reflections - going to scan these urls:
[info] file:/Users/fayimora/Code/Brutehack/brutehack-backend/target/scala-2.11/classes/
[info] 09:16:36.214 [main] DEBUG org.reflections.Reflections - could not scan file conf/production.conf in url file:/Users/fayimora/Code/Brutehack/brutehack-backend/target/scala-2.11/classes/ with scanner TypeAnnotationsScanner
[info] 09:16:36.215 [main] DEBUG org.reflections.Reflections - could not scan file conf/production.conf in url file:/Users/fayimora/Code/Brutehack/brutehack-backend/target/scala-2.11/classes/ with scanner MethodAnnotationsScanner
[info] 09:16:36.215 [main] DEBUG org.reflections.Reflections - could not scan file conf/production.conf in url file:/Users/fayimora/Code/Brutehack/brutehack-backend/target/scala-2.11/classes/ with scanner MethodParameterScanner
[info] 09:16:36.215 [main] DEBUG org.reflections.Reflections - could not scan file conf/production.conf in url file:/Users/fayimora/Code/Brutehack/brutehack-backend/target/scala-2.11/classes/ with scanner FieldAnnotationsScanner
[info] 09:16:36.216 [main] DEBUG org.reflections.Reflections - could not scan file conf/development.conf in url file:/Users/fayimora/Code/Brutehack/brutehack-backend/target/scala-2.11/classes/ with scanner TypeAnnotationsScanner
[info] 09:16:36.216 [main] DEBUG org.reflections.Reflections - could not scan file conf/development.conf in url file:/Users/fayimora/Code/Brutehack/brutehack-backend/target/scala-2.11/classes/ with scanner MethodAnnotationsScanner
[info] 09:16:36.216 [main] DEBUG org.reflections.Reflections - could not scan file conf/development.conf in url file:/Users/fayimora/Code/Brutehack/brutehack-backend/target/scala-2.11/classes/ with scanner MethodParameterScanner
[info] 09:16:36.216 [main] DEBUG org.reflections.Reflections - could not scan file conf/development.conf in url file:/Users/fayimora/Code/Brutehack/brutehack-backend/target/scala-2.11/classes/ with scanner FieldAnnotationsScanner
[info] 09:16:36.291 [main] INFO  org.reflections.Reflections - Reflections took 115 ms to scan 1 urls, producing 206 keys and 2483 values

Have you been able to use typesafe-config in a jar previously?

from typesafeconfig-guice.

racc avatar racc commented on August 22, 2024

No I'm pretty sure that warning just means that all packages will be searched. Although you could instantiate TypesafeConfigModule using the static method TypesafeConfigModule.fromConfig(config, "com.brutehack") to restrict the classpath searching to just your classes.

In truth, I haven't used Typesafe Config Module in a jar before.

Maybe if you have your own fork of TypesafeConfigModule, you could debug the TypesafeConfigModule.bindValue method and print out annotation to see if it is getting bound when the Guice Injector is being created? I'm assuming that when you run it directly stuff will be printed out, and when you run from the Jar it won't be printed out.

from typesafeconfig-guice.

racc avatar racc commented on August 22, 2024

@fayimora Maybe this is worth a shot, try running your jar file like so:
java -Dconfig.file=src/main/resources/conf/development.conf -classpath target/scala-2.11/brutehack.jar <MainClassHere>

from typesafeconfig-guice.

fayimora avatar fayimora commented on August 22, 2024

Just an FYI that I haven't abandoned this, yet. Just got busy with other projects that don't depend on this plugin.

from typesafeconfig-guice.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.