Gerrit plugin dependencies

115 views
Skip to first unread message

WekTorALL

unread,
Aug 19, 2016, 4:02:16 AM8/19/16
to Repo and Gerrit Discussion
Hi guys, 

I am trying to add some external libraries to a Gerrit plugin. 
1. I have extracted the jar files into //plugins/<plugin-name>/lib/
2. I have an entry for each jar in //plugins/<plugin-name>/BUCK like this: 
provided_deps = [
    '//plugins/jira-validator/lib:jira-client-0.5',
]
3. In //plugins/<plugin-name>/lib/BUCK I have added:
prebuilt_jar(
  name = 'jira-client-0.5',
  binary_jar = 'jira-client-0.5.jar',
  visibility = [
    'PUBLIC',
  ],
)

Now the build is working, but when I am trying to test this plugin in Gerrit, I get a NoClassDefFoundError, even if I add those libraries in the same way as described above. To be more specific, I get this error:
java.util.concurrent.ExecutionException: java.lang.NoClassDefFoundError: net/sf/json/JSON
even if I add json-lib to the BUCK files.
I tried to create a separate Java project and to use those libraries, and is working by including jar files in Eclipse build path, as usual.
Is there any way to include dependency of an dependency in my plugin?

Edwin Kempin

unread,
Aug 19, 2016, 4:25:08 AM8/19/16
to WekTorALL, Repo and Gerrit Discussion
On Fri, Aug 19, 2016 at 10:02 AM, WekTorALL <wekt...@gmail.com> wrote:
Hi guys, 

I am trying to add some external libraries to a Gerrit plugin. 
1. I have extracted the jar files into //plugins/<plugin-name>/lib/
2. I have an entry for each jar in //plugins/<plugin-name>/BUCK like this: 
provided_deps = [
I think you want this to be 'deps'.
'provided_deps' means that this library is only available at compile time and for runtime you rely on this library being there because it's already included in Gerrit core, but Gerrit core doesn't pack this library.
 
    '//plugins/jira-validator/lib:jira-client-0.5',
]
3. In //plugins/<plugin-name>/lib/BUCK I have added:
prebuilt_jar(
  name = 'jira-client-0.5',
  binary_jar = 'jira-client-0.5.jar',
  visibility = [
    'PUBLIC',
  ],
)

Now the build is working, but when I am trying to test this plugin in Gerrit, I get a NoClassDefFoundError, even if I add those libraries in the same way as described above. To be more specific, I get this error:
java.util.concurrent.ExecutionException: java.lang.NoClassDefFoundError: net/sf/json/JSON
even if I add json-lib to the BUCK files.
I tried to create a separate Java project and to use those libraries, and is working by including jar files in Eclipse build path, as usual.
Is there any way to include dependency of an dependency in my plugin?

--
--
To unsubscribe, email repo-discuss+unsubscribe@googlegroups.com
More info at http://groups.google.com/group/repo-discuss?hl=en

---
You received this message because you are subscribed to the Google Groups "Repo and Gerrit Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to repo-discuss+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


WekTorALL

unread,
Aug 19, 2016, 5:55:32 AM8/19/16
to Repo and Gerrit Discussion
I tried, same error...

-- 
--
To unsubscribe, email repo-discuss...@googlegroups.com

More info at http://groups.google.com/group/repo-discuss?hl=en

---
You received this message because you are subscribed to the Google Groups "Repo and Gerrit Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to repo-discuss...@googlegroups.com.

David Ostrovsky

unread,
Aug 19, 2016, 6:04:51 AM8/19/16
to Repo and Gerrit Discussion

Am Freitag, 19. August 2016 11:55:32 UTC+2 schrieb WekTorALL:
I tried, same error...

Can you share your gerrit_plugin() rule? As Edwin pointed out, changing
provided_deps to deps and rebuilding the plugin should just work.

As a test look inside the built plugin with jar -tf buck-out/gen/plugins/<plugin-name>/<plugin-name>.jar
the dependencies should be included.

WekTorALL

unread,
Aug 19, 2016, 6:23:54 AM8/19/16
to Repo and Gerrit Discussion


On Friday, August 19, 2016 at 1:04:51 PM UTC+3, David Ostrovsky wrote:

Am Freitag, 19. August 2016 11:55:32 UTC+2 schrieb WekTorALL:
I tried, same error...

Can you share your gerrit_plugin() rule? As Edwin pointed out, changing
provided_deps to deps and rebuilding the plugin should just work.
 
Shure:

include_defs('//lib/maven.defs')

gerrit_plugin(
  name = 'jira-validator',
  srcs = glob(['src/main/java/**/*.java']),
  resources = glob(['src/main/resources/**/*']),
  manifest_entries = [
    'Gerrit-PluginName: jira-validator',
  ],
  
  deps = [
    '//plugins/jira-validator/lib:commons-beanutils-1.9.2',
    '//plugins/jira-validator/lib:json-lib-2.4-jdk15',
    '//plugins/jira-validator/lib:jira-client-0.5',
    '//plugins/jira-validator/lib:ezmorph-1.0.4',
    '//plugins/jira-validator/lib:commons-codec-1.9',
    '//plugins/jira-validator/lib:commons-collections4-4.1',
    '//plugins/jira-validator/lib:commons-collections-3.2.2',
    '//plugins/jira-validator/lib:commons-lang-2.6',
    '//plugins/jira-validator/lib:commons-logging-1.2',
    '//plugins/jira-validator/lib:fluent-hc-4.5.2',
    '//plugins/jira-validator/lib:httpclient-4.5.2',
    '//plugins/jira-validator/lib:httpclient-cache-4.5.2',
    '//plugins/jira-validator/lib:httpclient-win-4.5.2',
    '//plugins/jira-validator/lib:httpcore-4.4.4',
    '//plugins/jira-validator/lib:httpmime-4.5.2',
    '//plugins/jira-validator/lib:jna-4.1.0',
    '//plugins/jira-validator/lib:jna-platform-4.1.0',
  ],
  
)

 
As a test look inside the built plugin with jar -tf buck-out/gen/plugins/<plugin-name>/<plugin-name>.jar
the dependencies should be included.
All dependencies are there...

I tried a buck clean, and then i built the plugin again, and now I have another error:
Caused by: java.lang.NoClassDefFoundError: Could not initialize class net.sf.json.JsonConfig

What am I doing wrong?...

David Ostrovsky

unread,
Aug 19, 2016, 7:47:04 AM8/19/16
to Repo and Gerrit Discussion

Am Freitag, 19. August 2016 12:23:54 UTC+2 schrieb WekTorALL:


On Friday, August 19, 2016 at 1:04:51 PM UTC+3, David Ostrovsky wrote:

Am Freitag, 19. August 2016 11:55:32 UTC+2 schrieb WekTorALL:
I tried, same error...

Can you share your gerrit_plugin() rule? As Edwin pointed out, changing
provided_deps to deps and rebuilding the plugin should just work.

[...]

 
As a test look inside the built plugin with jar -tf buck-out/gen/plugins/<plugin-name>/<plugin-name>.jar
the dependencies should be included.
All dependencies are there...
 
I tried a buck clean, and then i built the plugin again, and now I have another error:
Caused by: java.lang.NoClassDefFoundError: Could not initialize class net.sf.json.JsonConfig

What am I doing wrong?...

Missing a dependency? Note that Buck doesn't pull any transitive dependencies for libraries you provide.

WekTorALL

unread,
Aug 19, 2016, 9:45:00 AM8/19/16
to Repo and Gerrit Discussion
I dont know how and why, but it worked... I rebuilt the plugin after a buck clean, maybe this was the final problem?... Anyway, big thanks for your help, guys! 
Reply all
Reply to author
Forward
0 new messages