Cargo build for JBoss 5.1.0.GA fails: cannot find ClientLoginModule

Hey,

Following a previous post on deploying to a remote JBoss 5 with Cargo and the cargo gradle plugin, I have now an issue whith a classNotFound:

Caused by: javax.security.auth.login.LoginException: classe LoginModule introuvable : org.jboss.security.ClientLoginModule

When looking at the code for JBossDeployer.java:176 (source)

176        new LoginContext("jboss-jaas", null,
177            new UsernamePasswordCallbackHandler(this.configuration),
178            new JaasConfiguration(new AppConfigurationEntry(
179                "org.jboss.security.ClientLoginModule",
180                AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,
181                Collections.EMPTY_MAP))).login();

and ClientLoginModule to understand which class LoginModule is not found (source), I see the import :

import javax.security.auth.spi.LoginModule;

The problem is that in the dependencies I have defined the cargo dependencies and the JBoss5 remote deployer dependencies, which include JAAS 1.0.01 :

[gerald@archie testapp]$ gradle dependencyInsight --configuration cargo --dependency jaas
:dependencyInsight
javax.security:jaas:1.0.01
\--- org.jboss.jbossas:jboss-as-security:5.1.0.GA
     \--- org.jboss.jbossas:jboss-as-jbossas-remoting:5.1.0.GA
          \--- cargo

, which include the LoginModule class:

[gerald@archie testapp]$ jar -tvf /home/gerald/.gradle/caches/modules-2/files-2.1/javax.security/jaas/1.0.01/7cb33f63887083c80f6d01df67ad5993094d8586/jaas-1.0.01.jar | grep LoginModule
  1228 Thu Jan 30 17:39:56 CET 2003 javax/security/auth/login/AppConfigurationEntry$LoginModuleControlFlag.class
   430 Thu Jan 30 17:40:20 CET 2003 javax/security/auth/spi/LoginModule.class

Any idea why the JBossDeployer class does not find the LoginModule class ??

Here is the console :

[gerald@archie testapp]$ gradle cargoDeployRemote
:cargoDeployRemote FAILED

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ‘:cargoDeployRemote’.
    org.codehaus.cargo.util.CargoException: Cannot deploy deployable org.codehaus.cargo.container.jboss.deployable.JBossWAR[testapp.war]
  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 2.928 secs
[gerald@archie testapp]$ gradle cargoDeployRemote -s
:cargoDeployRemote FAILED

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ‘:cargoDeployRemote’.
    org.codehaus.cargo.util.CargoException: Cannot deploy deployable org.codehaus.cargo.container.jboss.deployable.JBossWAR[testapp.war]
  • Try:
    Run with --info or --debug option to get more log output.
  • Exception is:
    org.gradle.api.tasks.TaskExecutionException: Execution failed for task ‘:cargoDeployRemote’.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
    at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:305)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.java:79)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:63)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:51)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:23)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:88)
    at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:29)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:62)
    at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
    at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:68)
    at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:62)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:55)
    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:149)
    at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:106)
    at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:86)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:80)
    at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33)
    at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:36)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
    at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:47)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
    at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:35)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
    at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:24)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
    at org.gradle.launcher.daemon.server.exec.StartStopIfBuildAndStop.execute(StartStopIfBuildAndStop.java:33)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:71)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:69)
    at org.gradle.util.Swapper.swap(Swapper.java:38)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:69)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
    at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:60)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
    at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:70)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
    at org.gradle.launcher.daemon.server.exec.DaemonHygieneAction.execute(DaemonHygieneAction.java:39)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
    at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:46)
    at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:246)
    at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:64)
    Caused by: : org.codehaus.cargo.util.CargoException: Cannot deploy deployable org.codehaus.cargo.container.jboss.deployable.JBossWAR[testapp.war]
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:116)
    at org.gradle.api.internal.project.ant.BasicAntBuilder.nodeCompleted(BasicAntBuilder.java:77)
    at org.gradle.api.internal.project.ant.BasicAntBuilder.doInvokeMethod(BasicAntBuilder.java:92)
    at com.bmuschko.gradle.cargo.tasks.remote.RemoteCargoContainerTask.runAction(RemoteCargoContainerTask.groovy:82)
    at com.bmuschko.gradle.cargo.tasks.AbstractCargoContainerTask$_start_closure2.doCall(AbstractCargoContainerTask.groovy:93)
    at com.bmuschko.gradle.cargo.tasks.AbstractCargoContainerTask$_start_closure2.doCall(AbstractCargoContainerTask.groovy)
    at com.bmuschko.gradle.cargo.util.LoggingHandler.withAntLoggingListener(LoggingHandler.groovy:36)
    at com.bmuschko.gradle.cargo.util.LoggingHandler$withAntLoggingListener.call(Unknown Source)
    at com.bmuschko.gradle.cargo.tasks.AbstractCargoContainerTask.start(AbstractCargoContainerTask.groovy:92)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:63)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.doExecute(AnnotationProcessingTaskFactory.java:218)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:211)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:200)
    at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:579)
    at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:562)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
    … 54 more
    Caused by: org.codehaus.cargo.util.CargoException: Cannot deploy deployable org.codehaus.cargo.container.jboss.deployable.JBossWAR[testapp.war]
    at org.codehaus.cargo.container.jboss.JBoss5xRemoteDeployer.deploy(JBoss5xRemoteDeployer.java:216)
    at org.codehaus.cargo.ant.CargoTask.executeActions(CargoTask.java:603)
    at org.codehaus.cargo.ant.CargoTask.execute(CargoTask.java:513)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    … 70 more
    Caused by: javax.security.auth.login.LoginException: classe LoginModule introuvable : org.jboss.security.ClientLoginModule
    at org.codehaus.cargo.tools.jboss.JBossDeployer.getDeploymentManager(JBossDeployer.java:176)
    at org.codehaus.cargo.tools.jboss.JBossDeployer.deploy(JBossDeployer.java:71)
    at org.codehaus.cargo.container.jboss.JBoss5xRemoteDeployer.deploy(JBoss5xRemoteDeployer.java:212)
    … 74 more

BUILD FAILED

Total time: 2.236 secs

And here is the gradle build file:

apply plugin: 'war'
apply plugin: 'com.bmuschko.cargo'

buildscript {
    repositories {
	maven{
          url "https://nexus.lbg.office.lyra/content/groups/vad_repo/"
        }        
    }
    dependencies {
        classpath 'com.bmuschko:gradle-cargo-plugin:2.1.1'
    }
}

repositories {
   maven{
         url "https://nexus.lbg.office.lyra/content/groups/vad_repo/"
   }
}

dependencies {
  def cargoVersion = '1.4.5'
  cargo "org.codehaus.cargo:cargo-core-uberjar:$cargoVersion", "org.codehaus.cargo:cargo-ant:$cargoVersion"
  cargo 'org.jboss.jbossas:jboss-as-jbossas-remoting:5.1.0.GA'
}

cargo {
    containerId = 'jboss5x'
    port = 8080
    
    remote {
      username = "admin"
      password = "admin"
      hostname = "10.0.2.2"
    }

    deployable {
        context = 'myawesomewebapp'
    }
}

No idea. Looks proper to me. I’d ask on the Cargo user mailing list which JBoss dependencies are actually required for remote deployment.

Thanks for your feedback.

I have asked on the Cargo user mailing list, but the activity on this mailing list is near absolute zero…

I wanted to try to understand what’s going on and why cargo cannot find the class in its classpath.
I suspect there is some trick about classloaders and dependency management, between buildscript classpath, and cargo configuration, but I am new to Gradle and don’t really understand what’s going on behind the scene.

How could I check the actual classpath/classloader used for cargo task launch ?

BTW, I’ve checked the debug logs when runningGradle build, and it talks about classloaders.
From what I see, it finds the class javax.security.auth.login.AppConfigurationEntry which should lie near the LoginModule class in the jaas-1.0.01.jar dependency…

[gerald@archie testapp]$ jar -tvf /home/gerald/.gradle/caches/modules-2/files-2.1/javax.security/jaas/1.0.01/7cb33f63887083c80f6d01df67ad5993094d8586/jaas-1.0.01.jar | grep AppConfiguration
  1228 Thu Jan 30 17:39:56 CET 2003 javax/security/auth/login/AppConfigurationEntry$LoginModuleControlFlag.class
  1747 Thu Jan 30 17:39:56 CET 2003 javax/security/auth/login/AppConfigurationEntry.class

15:30:40.662 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] Class javax.security.auth.login.LoginContext loaded from parent loader (parentFirst)
15:30:40.662 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] Finding class org.codehaus.cargo.container.jboss.internal.UsernamePasswordCallbackHandler
15:30:40.662 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] Loaded from /home/gerald/.gradle/caches/modules-2/files-2.1/org.codehaus.cargo/cargo-core-uberjar/1.4.5/c776415cfbdeb6e34412eb5e5030af
4ac3ea22b4/cargo-core-uberjar-1.4.5.jar org/codehaus/cargo/container/jboss/internal/UsernamePasswordCallbackHandler.class
15:30:40.663 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] Class javax.security.auth.callback.CallbackHandler loaded from parent loader (parentFirst)
15:30:40.663 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] Class org.codehaus.cargo.container.jboss.internal.UsernamePasswordCallbackHandler loaded from ant loader (parentFirst)
15:30:40.663 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] Class javax.security.auth.callback.UnsupportedCallbackException loaded from parent loader (parentFirst)
15:30:40.663 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] Class javax.security.auth.login.AppConfigurationEntry loaded from parent loader (parentFirst)
15:30:40.663 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] Class javax.security.auth.login.AppConfigurationEntry$LoginModuleControlFlag loaded from parent loader (parentFirst)
15:30:40.663 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] Class javax.security.auth.login.AppConfigurationEntry loaded from parent loader (parentFirst)
15:30:40.664 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter] Finished executing task ':cargoDeployRemote’
15:30:40.664 [LIFECYCLE] [class org.gradle.TaskExecutionLogger] :cargoDeployRemote FAILED

Ok, the more I investigate this thing, the more I think it’s a bug of cargo…

First, I was wrong about the class not being found: it’s indeed “org.jboss.security.ClientLoginModule” that is not found, not LoginModule.

I wrote a simple Ant build file to short-circuit Gradle and the Gradle Cargo plugin:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE project>
<project name="testapp-deploy" default="deploy">

<taskdef resource="cargo.tasks">
  <classpath>
    <pathelement location="antlib/cargo-core-uberjar-1.4.5.jar"/>
    <pathelement location="antlib/cargo-ant-1.4.5.jar"/>
    <!-- More dependencies needed, we get them -->
    <pathelement path="antlib/commons-discovery-0.4.jar" />
    <pathelement path="antlib/commons-logging-1.1.1.jar" />
    <pathelement path="antlib/xercesImpl-2.4.0.jar" />
    <pathelement path="antlib/dom4j-1.6.1.jar" />
    <pathelement path="antlib/jaxen-1.1.2.jar" />
    <pathelement path="antlib/jnp-client-5.0.3.GA.jar" />
    <pathelement path="antlib/jboss-profileservice-spi-5.1.0.GA.jar"/>
    <pathelement path="antlib/jbosssx-client-2.0.3.SP1.jar"/>
  </classpath>
</taskdef>

<target name="deploy">

<echo>Deploying war file to remote JBoss...</echo>

<cargo containerId="jboss51x" action="deploy" type="remote">
  <configuration type="runtime">
    <property name="cargo.hostname" value="10.0.2.2"/>
    <property name="cargo.servlet.port" value="8080"/>
    <property name="cargo.remote.username" value="admin"/>
    <property name="cargo.remote.password" value="admin"/>
    <deployable type="war" file="build/libs/testapp.war">
      <property name="context" value="mytestapp"/>
    </deployable>
  </configuration>
</cargo>

</target>

</project>

Guess what the output is when I run ant ?

This one:

[gerald@archie testapp]$ ant
Buildfile: /home/gerald/svn2git/automatic/testapp/build.xml

deploy:
[echo] Deploying war file to remote JBoss…

BUILD FAILED
/home/gerald/svn2git/automatic/testapp/build.xml:25: org.codehaus.cargo.util.CargoException: Cannot deploy deployable org.codehaus.cargo.container.jboss.deployable.JBossWAR[testapp.war]
at org.codehaus.cargo.container.jboss.JBoss5xRemoteDeployer.deploy(JBoss5xRemoteDeployer.java:216)
at org.codehaus.cargo.ant.CargoTask.executeActions(CargoTask.java:603)
at org.codehaus.cargo.ant.CargoTask.execute(CargoTask.java:513)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:435)
at org.apache.tools.ant.Target.performTasks(Target.java:456)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1405)
at org.apache.tools.ant.Project.executeTarget(Project.java:1376)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1260)
at org.apache.tools.ant.Main.runBuild(Main.java:853)
at org.apache.tools.ant.Main.startAnt(Main.java:235)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:285)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:112)
Caused by: javax.security.auth.login.LoginException: classe LoginModule introuvable : org.jboss.security.ClientLoginModule
at javax.security.auth.login.LoginContext.invoke(LoginContext.java:800)
at javax.security.auth.login.LoginContext.access$000(LoginContext.java:203)
at javax.security.auth.login.LoginContext$4.run(LoginContext.java:690)
at javax.security.auth.login.LoginContext$4.run(LoginContext.java:688)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.login.LoginContext.invokePriv(LoginContext.java:687)
at javax.security.auth.login.LoginContext.login(LoginContext.java:595)
at org.codehaus.cargo.tools.jboss.JBossDeployer.getDeploymentManager(JBossDeployer.java:176)
at org.codehaus.cargo.tools.jboss.JBossDeployer.deploy(JBossDeployer.java:70)
at org.codehaus.cargo.container.jboss.JBoss5xRemoteDeployer.deploy(JBoss5xRemoteDeployer.java:212)
… 19 more
javax.security.auth.login.LoginException: classe LoginModule introuvable : org.jboss.security.ClientLoginModule
at javax.security.auth.login.LoginContext.invoke(LoginContext.java:800)
at javax.security.auth.login.LoginContext.access$000(LoginContext.java:203)
at javax.security.auth.login.LoginContext$4.run(LoginContext.java:690)
at javax.security.auth.login.LoginContext$4.run(LoginContext.java:688)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.login.LoginContext.invokePriv(LoginContext.java:687)
at javax.security.auth.login.LoginContext.login(LoginContext.java:595)
at org.codehaus.cargo.tools.jboss.JBossDeployer.getDeploymentManager(JBossDeployer.java:176)
at org.codehaus.cargo.tools.jboss.JBossDeployer.deploy(JBossDeployer.java:70)
at org.codehaus.cargo.container.jboss.JBoss5xRemoteDeployer.deploy(JBoss5xRemoteDeployer.java:212)
at org.codehaus.cargo.ant.CargoTask.executeActions(CargoTask.java:603)
at org.codehaus.cargo.ant.CargoTask.execute(CargoTask.java:513)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:435)
at org.apache.tools.ant.Target.performTasks(Target.java:456)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1405)
at org.apache.tools.ant.Project.executeTarget(Project.java:1376)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1260)
at org.apache.tools.ant.Main.runBuild(Main.java:853)
at org.apache.tools.ant.Main.startAnt(Main.java:235)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:285)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:112)

Total time: 1 second

Hmm, not very surprised here… but we know the jbosssx-client-2.0.3.SP1.jar contains the ClientLoginModule, so what’s happening ??

If I mess with the ant classpath (editing /etc/apache-ant/ant.conf on my ArchLinux system) adding the jbosssx-client jar, it finally finds the ClientLoginModule class !

But fails with:

Caused by: java.lang.ClassNotFoundException: org.jboss.logging.Logger
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
… 32 more

So, it seems that the classloader used by cargo during execution depends on the ant classpath, not the dependencies specified in the task definition…

Benjamin, if you read this, would it be possible to add some kind of option in your plugin to allow us to specify additional jars for launching the ant process which is the base of your plugin ? or maybe an option to include all the dependencies defined in the “cargo” configuration for launching ant ?

I know the problem is not linked with your plugin, but maybe the solution can be :wink:

Maybe linked to this Gradle issue 2312 ?

Ok, it works now, thanks to the workaround proposed by René Groeschke in this post:

In my case, it takes a configuration and injects the resolved files in the Ant classloader:

  ClassLoader antClassLoader = org.apache.tools.ant.Project.class.classLoader
                 configurations.cargo.each { File f ->
                         antClassLoader.addURL(f.toURI().toURL())
                 }

After some struggle with dependencies conflicts, I got the following script to successfully deploy on my jboss:

apply plugin: 'war'
apply plugin: 'com.bmuschko.cargo'

buildscript {
    repositories {
        maven{
          url "https://nexus.lbg.office.lyra/content/groups/vad_repo/"
        }
    }
    dependencies {
        classpath 'com.bmuschko:gradle-cargo-plugin:2.1.1'
  }
}

repositories {
   maven{
         url "https://nexus.lbg.office.lyra/content/groups/vad_repo/"
   }
}

configurations {
  antcp
}

configurations.all {
  resolutionStrategy {
    // add dependency substitution rules
    dependencySubstitution {
      //specifying a fixed version for all libraries with 'org.gradle' group
      eachModule { ModuleDependencySubstitution details ->
        if (details.requested.group == 'commons-logging') {
          details.useVersion '1.1.1'
        }
        if (details.requested.module == 'jboss-common-core') {
          details.useVersion '2.2.14.GA'
        }
        if (details.requested.module == 'jboss-logging-spi') {
          details.useVersion '2.1.0.GA'
        }
      }
    }
  }
}

dependencies {
  def cargoVersion = '1.4.5'
  cargo "org.codehaus.cargo:cargo-core-uberjar:$cargoVersion", "org.codehaus.cargo:cargo-ant:$cargoVersion"
  cargo 'org.jboss.jbossas:jboss-as-jbossas-remoting:5.1.0.GA'

  antcp 'org.jboss.jbossas:jboss-as-jbossas-remoting:5.1.0.GA'
  antcp 'org.jboss.jbossas:jboss-as-client:5.1.0.GA'
}

ClassLoader antClassLoader = org.apache.tools.ant.Project.class.classLoader
                 configurations.antcp.each { File f ->
                         antClassLoader.addURL(f.toURI().toURL())
                 }

cargo {
    containerId = 'jboss51x'
    port = 1099

    remote {
      username = "admin"
      password = "admin"
      hostname = "127.0.0.1"
    }

    deployable {
        context = 'myawesomewebapp'
    }

}

Hope it helps !