升级Slack依赖后TeamCity插件运行时出现NoClassDefFoundError求助
NoClassDefFoundError for SlackWebSocketSessionImpl in Your TeamCity Plugin Let's work through this issue step by step. That "Could not initialize class" error isn't just about missing classes—it usually means the class attempted to load but failed during initialization (like a static code block throwing an exception, or a hidden dependency conflict). Here are actionable fixes to try:
1. Uncover the root initialization failure
First, let's get clearer context on why the class won't initialize:
- Check your TeamCity server logs (look in
logs/teamcity-server.logor enable debug logs) for the full stack trace. TheNoClassDefFoundErroris often a secondary error caused by anExceptionInInitializerErrorthat happened behind the scenes. - Run your plugin locally in a TeamCity development instance with debug mode enabled. Set a breakpoint on
SlackSessionFactory.createWebSocketSlackSession(config.oauthKey)and step through to see exactly which part ofSlackWebSocketSessionImpl's static initialization is failing.
2. Ensure all transitive dependencies are packaged
The 1.2.0 version of com.ullink.slack.simpleslackapi likely added or updated transitive dependencies that weren't present in 0.5.2:
- Run
mvn dependency:treein your project to list all dependencies for 1.2.0. Compare it to the 0.5.2 dependency tree to spot missing jars (like newer Netty versions, Jackson modules, or utility libraries). - Double-check your
plugin-assembly.xmlto confirm it's including all runtime dependencies. Make sure you have a dependency set that captures transitive runtime jars:<dependencySets> <dependencySet> <outputDirectory>lib</outputDirectory> <scope>runtime</scope> <useProjectArtifact>false</useProjectArtifact> <unpack>false</unpack> </dependencySet> </dependencySets> - After packaging, extract your plugin zip/jar and verify the
libfolder containssimpleslackapi-1.2.0.jarplus all its required transitive dependencies (e.g.,netty-all,jackson-databind).
3. Resolve classloader conflicts with TeamCity's built-in libraries
TeamCity ships with its own versions of common libraries (like Netty, Jackson) that can clash with your plugin's dependencies. This is a common pain point:
- Use
maven-shade-pluginto relocate conflicting packages. For example, rename Netty or Jackson packages inside your plugin so they don't collide with TeamCity's versions:<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>3.4.1</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <relocations> <relocation> <pattern>io.netty</pattern> <shadedPattern>com.yourplugin.io.netty</shadedPattern> </relocation> <relocation> <pattern>com.fasterxml.jackson</pattern> <shadedPattern>com.yourplugin.fasterxml.jackson</shadedPattern> </relocation> </relocations> </configuration> </execution> </executions> </plugin> - Update your plugin's
plugin.xmlto use plugin-first classloading. Add this inside the<plugin>element to prioritize your plugin's libraries over TeamCity's:<classLoader>plugin</classLoader>
4. Validate your Maven dependency scope
Make sure your Slack API dependency isn't marked as provided (since TeamCity doesn't include this library out of the box):
<dependency> <groupId>com.ullink.slack</groupId> <artifactId>simpleslackapi</artifactId> <version>1.2.0</version> <scope>runtime</scope> <!-- or compile --> </dependency>
5. Test with a minimal standalone app
Create a tiny Scala app that just calls SlackSessionFactory.createWebSocketSlackSession(...) with the 1.2.0 dependency. If this works, the issue is specific to the TeamCity plugin environment (classloader conflicts or packaging gaps). If it fails, the problem lies with the Slack API version itself or its direct dependencies.
内容的提问来源于stack exchange,提问作者alexkvak

