Gradle provided dependencies present in war - jboss5.x

I would like to set several dependencies in my war as provided because theses jar are provided by the server.
So I set my build.gradle like this:
apply plugin: 'war'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'eclipse-wtp'
dependencies {
compile project(':project1')
providedCompile 'xml-apis:xml-apis:2.0.2',
'javax.servlet:servlet-api:2.5',
'javax.servlet.jsp:jsp-api:2.1',
'javax.servlet:jstl:1.2',
'com.sun.faces:jsf-api:2.1.6',
'com.sun.faces:jsf-impl:2.1.6',
'javax.transaction:jta:1.1'
}
But when I deploy my generated war in my server, all jars set in provided are present and my server doesn't start.
What is wrong in my configuration ?
Thanks.

Looks correct, and works fine for me. Chances are that the problem is somewhere else.

Related

Using Gradle for Scala and ScalaTest (IntelliJ 2016.3.6)

Here is a quick build.gradle file I put together:
apply plugin: 'scala'
apply plugin: 'idea'
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
compile "org.scala-lang:scala-library:2.12.2"
compile "org.scala-lang:scala-compiler:2.12.2"
testCompile 'org.scalatest:scalatest_2.11:3.0.1'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
If understood correctly, when running gradle idea, the external dependencies defined above appear in the External Libraries folder.
While I do see the dependencies in the folder, the issue I am facing is that I am unable to import anything from my external libraries provided by Gradle. Anything I manually provide (i.e. a downloaded version of the Scala SDK) works perfectly fine.
I have src and test marked as my sources root and test sources root, respectively.
What could possibly be the issue? Detailed explanations are also appreciated; I'm coming from a Maven background and struggling with the Gradle documentation.

Gradle: add .jar to /war/WEB-INF/lib

I'm having difficulty getting Gradle to add a dependency to my /war/WEB-INF/lib directory in a Google Web Application Project.
apply plugin: 'java'
apply plugin: 'war'
repositories {
mavenCentral()
}
dependencies {
compile 'com.google.code.gson:gson:2.2.4'
}
Using Eclipse, gson-2.2.4.jar shows up in Project and External Dependencies (project compiles) but doesn't get added to /war/WEB-INF/lib (NoClassDef exception at runtime since it can't find the .jar)
I've tried changing webAppDir, webAppDirName, and editing the war task all to no avail.

Where do I apply the gradle idea plugin?

The documentation says:
apply plugin: 'idea'
This is easy but not very useful. It does not tell me where to apply the plug-in, for example. allProjects, perhaps? subprojects? Are there any places where it should not be applied?
Typically all plugins are applied just after buildscript section at the very top of build.gradle script, especially in single module projects.
In multimodule projects you can apply the plugin in both allprojects and subprojects. It just depends if this plugin will be required in all the projects. If not and it's applied - nothing bad happens.

Tomcat not booting up Gradle Webapp

I have a Gradle webapp having plugin war and jetty defined in build.gradle, as follows:
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'jetty'
group = 'com.company'
sourceCompatibility = 1.8
targetCompatibility = 1.8
version = '1.0'
war.baseName = 'deploy'
repositories {
mavenLocal()
mavenCentral()
maven { url "http://repository.pentaho.org/artifactory/repo/" }
}
dependencies {
..
}
When I perform a gradle build with jettyRunWar, as follows:
$ ./gradlew jettyRunWar
It build the application and deploy it to Jetty as expected.
Now I want to deploy the same application to Tomcat7 as well, to do the same, I ran the gradle war task as follows:
$ ./gradlew war
after running the task, I can see the deploy-1.0.war inside /Users/ArpitAggarwal/deploy/build/libs/ and when I tried to deploy it to Tomcat7, it's not picked up by Tomcat.
My question is - Do I need to apply any additional plugin to make the application deployable to Tomcat7?
Thanks.
war plug-in only creates a war, it doesn't deploy generated war to tomcat by itself.
You can create a task to deploy war to tomcat.
task deployToTomcat(type: Copy) {
from war.archivePath
into "${tomcatHome}/webapps"
}
You can also use gradle-tomcat-plugin.
The problem is contextRoot of .war file. Gradle generates the contextRoot of .war file picking the war.baseName and version, so the contextRoot is changed to deploy-1.0 and the application is accessible at:
localhost:8080/deploy-1.0
Then I removed the version field from build.gradle which makes Gradle generate .war with contextRoot as deploy and application accessibility at:
localhost:8080/deploy/

Using gradle to generate eclipse projects for EJB Module

I want to generate project and settings for a EAR project, a EJB client jar and a EJB module but i was not able to insert new facets to the eclipseWtp task, tried many combinations based on the documentation on gradle website.
tried things like the following and always got Premature end of file error.
eclipseWtp {
beforeConfigured { wtp ->
wtp.facets.add(new Facet('jst.ejb','3.1'))
}
}
eclipseWtp {
facet(['name':'jst.ejb','version':'3.1'])
}
Make sure that both war and eclipse plugins are applied on the project. Then it will work correctly, eg.:
apply plugin: 'war'
apply plugin: 'eclipse'
eclipseWtp.facet(name: 'jst.ejb', version: '3.1')