[GRADLE-2235] Programmatically configuring Jetty Plugin causes ClassCastException Created: 14/Apr/12  Updated: 16/Jan/17  Resolved: 16/Jan/17

Status: Resolved
Project: Gradle
Affects Version/s: None
Fix Version/s: None

Type: Bug
Reporter: Gradle Forums Assignee: Unassigned
Resolution: Won't Fix Votes: 0


 Description   

In gradle-1.0-milestone-3 I use to be able to configure the Jetty connectors programatically using the following build.gradle

apply plugin: 'jetty'

[jettyRun, jettyRunWar]*.configure {
def httpsConnector = new org.mortbay.jetty.security.SslSocketConnector()
connectors = [httpsConnector]
}

Now I'm trying to do something similar in gradle-1.0-milestone-8. Initially I had problems due to the fact that milestone 4 [had breaking classpath changes]([1]http://wiki.gradle.org/display/GRADLE.... I got past this by updating my build as shown below:

apply plugin: 'jetty'

buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.mortbay.jetty:jetty:6.1.25'
}
}
[jettyRun, jettyRunWar]*.configure {
def httpsConnector = new org.mortbay.jetty.security.SslSocketConnector()
connectors = [httpsConnector]
}

As you might have guessed, running a gradle build on the above build.groovy causes the ClassCastException displayed below. I believe this is since the two objects are loaded by different classloaders.

$ gradle -v

------------------------------------------------------------
Gradle 1.0-milestone-8
------------------------------------------------------------

Gradle build time: Monday, February 13, 2012 11:53:32 PM UTC
Groovy: 1.8.4
Ant: Apache Ant(TM) version 1.8.2 compiled on December 20 2010
Ivy: 2.2.0
JVM: 1.6.0_30 (Sun Microsystems Inc. 20.5-b03)
OS: Linux 3.0.0-16-generic-pae i386

$ gradle --stacktrace

FAILURE: Build failed with an exception.

  • Where:
    Build file '/home/rwinch/tmp/gradlejetty/build.gradle' line: 15
  • What went wrong:
    A problem occurred evaluating root project 'gradlejetty'.
    > Cannot cast object 'SslSocketConnector@0.0.0.0:0' with class 'org.mortbay.jetty.security.SslSocketConnector' to class 'org.mortbay.jetty.Connector'
  • Try:
    Run with --info or --debug option to get more log output.
  • Exception is:
    org.gradle.api.GradleScriptException: A problem occurred evaluating root project 'gradlejetty'.
    at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:54)
    at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:127)
    at org.gradle.configuration.BuildScriptProcessor.evaluate(BuildScriptProcessor.java:38)
    at org.gradle.configuration.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:43)
    at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:478)
    at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:75)
    at org.gradle.configuration.ProjectEvaluationConfigurer.execute(ProjectEvaluationConfigurer.java:23)
    at org.gradle.configuration.ProjectEvaluationConfigurer.execute(ProjectEvaluationConfigurer.java:21)
    at org.gradle.configuration.DefaultBuildConfigurer$1.execute(DefaultBuildConfigurer.java:38)
    at org.gradle.configuration.DefaultBuildConfigurer$1.execute(DefaultBuildConfigurer.java:35)
    at org.gradle.api.internal.project.AbstractProject.configure(AbstractProject.java:454)
    at org.gradle.api.internal.project.AbstractProject.allprojects(AbstractProject.java:449)
    at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:35)
    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:139)
    at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:110)
    at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:78)
    at org.gradle.launcher.cli.RunBuildAction.execute(RunBuildAction.java:42)
    at org.gradle.launcher.cli.RunBuildAction.execute(RunBuildAction.java:28)
    at org.gradle.launcher.exec.ExceptionReportingAction.execute(ExceptionReportingAction.java:32)
    at org.gradle.launcher.exec.ExceptionReportingAction.execute(ExceptionReportingAction.java:21)
    at org.gradle.launcher.cli.CommandLineActionFactory$WithLoggingAction.execute(CommandLineActionFactory.java:238)
    at org.gradle.launcher.cli.CommandLineActionFactory$WithLoggingAction.execute(CommandLineActionFactory.java:222)
    at org.gradle.launcher.Main.doAction(Main.java:48)
    at org.gradle.launcher.exec.EntryPoint$1.execute(EntryPoint.java:53)
    at org.gradle.launcher.exec.EntryPoint$1.execute(EntryPoint.java:51)
    at org.gradle.launcher.exec.Execution.execute(Execution.java:28)
    at org.gradle.launcher.exec.EntryPoint.run(EntryPoint.java:39)
    at org.gradle.launcher.Main.main(Main.java:39)
    at org.gradle.launcher.ProcessBootstrap.runNoExit(ProcessBootstrap.java:51)
    at org.gradle.launcher.ProcessBootstrap.run(ProcessBootstrap.java:33)
    at org.gradle.launcher.GradleMain.main(GradleMain.java:24)
    Caused by: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'SslSocketConnector@0.0.0.0:0' with class 'org.mortbay.jetty.security.SslSocketConnector' to class 'org.mortbay.jetty.Connector'
    at org.gradle.api.internal.BeanDynamicObject$MetaClassAdapter.setProperty(BeanDynamicObject.java:158)
    at org.gradle.api.internal.BeanDynamicObject.setProperty(BeanDynamicObject.java:87)
    at org.gradle.api.internal.CompositeDynamicObject.setProperty(CompositeDynamicObject.java:61)
    at org.gradle.api.plugins.jetty.JettyRun_Decorated.setProperty(Unknown Source)
    at build_573uimf509544bc987ptkhtenr$_run_closure1.doCall(/home/rwinch/tmp/gradlejetty/build.gradle:15)
    at org.gradle.util.ConfigureUtil.configure(ConfigureUtil.java:136)
    at org.gradle.util.ConfigureUtil.configure(ConfigureUtil.java:104)
    at org.gradle.api.internal.AbstractTask.configure(AbstractTask.java:410)
    at org.gradle.api.internal.AbstractTask.configure(AbstractTask.java:60)
    at build_573uimf509544bc987ptkhtenr.run(/home/rwinch/tmp/gradlejetty/build.gradle:12)
    at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:52)
    ... 30 more

I would prefer to programtically configure it since I want to dynamically allocate my ports for a CI build and doing so in configuration requires more hoops (filtering) to jump through. Is there a simple way to configure HTTPS for the Jetty Plugin programatically, or do I need to resort to using the XML configuration?

Note that I have not yet had the opportunity to try with m9, but plan to. It seems the download is going to take over 2 hours despite having fast connection to other sites. In short, I'm not certain yet if this issue is present in M9 and If someone has suggestions for getting this to work in M9 I would be happy to hear that as well.

PS: The closest issue on the forums and in JIRA I could find was GRADLE-1960

Thanks in advance,
Rob
----------------------------------------------------------------------------------------
[1] http://wiki.gradle.org/display/GRADLE/Gradle+1.0-milestone-4+Breaking+Changes#Gradle1.0-milestone-4BreakingChanges-Classpathchanges)



 Comments   
Comment by Gradle Forums [ 14/Apr/12 ]

For those interested, I was able to produce a very similar error with M9.

Comment by Gradle Forums [ 14/Apr/12 ]

I was also able to reproduce this issue on M9. Any ideas on how to configure SSL other than programatically.

Comment by Gradle Forums [ 14/Apr/12 ]

I kind of figured out how to set it it up programatically :

casServer.configure {
contextPath = "/cas"

jettyConfig = file("src/test/resources/jetty-web.xml")

webApp = casServerOverlay.customWar
inputs.file casServerOverlay.explodedWar

doFirst() {
System.setProperty('javax.net.ssl.trustStore', keystore)
System.setProperty('javax.net.ssl.trustStorePassword', password)
}
}

Comment by Benjamin Muschko [ 15/Nov/16 ]

As announced on the Gradle blog we are planning to completely migrate issues from JIRA to GitHub.

We intend to prioritize issues that are actionable and impactful while working more closely with the community. Many of our JIRA issues are inactionable or irrelevant. We would like to request your help to ensure we can appropriately prioritize JIRA issues you’ve contributed to.

Please confirm that you still advocate for your JIRA issue before December 10th, 2016 by:

  • Checking that your issues contain requisite context, impact, behaviors, and examples as described in our published guidelines.
  • Leave a comment on the JIRA issue or open a new GitHub issue confirming that the above is complete.

We look forward to collaborating with you more closely on GitHub. Thank you for your contribution to Gradle!

Comment by Benjamin Muschko [ 16/Jan/17 ]

The Jetty plugin has been deprecated and is scheduled to be removed with Gradle 4.0. We are not going to work on this issue anymore.

Generated at Wed Jun 30 12:16:25 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.