Unable to exclude Jar from grails war - gradle

I am using grails 4.0
In my build.gradle, I have following entry.
war {
exclude("**/abc-1.0.0.jar", "**/xyz-1.0.0.jar")
}
But for some reason, both these jars are included in the war file, when I run the command grails prod war
I have tried varies options, but nothing seems to work.

are you sure you're not trying to limit dependencies...?
ex.
dependencies {
...
compile("org.grails:grails-plugin-interceptors"){
exclude(module: 'org.slf4j:slf4j-api:1.7.22')
exclude(module: 'org.slf4j:jcl-over-slf4j:1.7.22')
}
}

Related

War task of Gradle build adding extra jars than those from dependencies in build.gradle

We have recently migrated to Gradle build and I have added a war that task that has web.xml and dependent jars along with jar created in the jar task.
task testWar(type: War)
{
archiveName 'test.war'
webXml = file('WebContent/WEB-INF/web.xml')
into ('WEB-INF/lib')
{
from configurations.compile
from jar
}
}
This creates the war but the size of WEB-INF/lib is double the size of the libs actually given in dependencies. It might be adding the jars that the dependent jars depend on. But Ant build just works fine with just the dependent jars.
Is there any way to create war with just the jars provided in dependencies?
Note: https://docs.gradle.org/current/userguide/war_plugin.html didnt help as I need all the jars in dependencies, just want to avoid extra dependent jars
You can use gradle dependencies to know which libraries are causing the inclusion of these additional dependencies.
Once you have that then simply exclude the dependency you want to remove from your package.
dependencies {
compile (group: 'org.quartz-scheduler', name: 'quartz', version: '2.3.0') {
exclude group: 'org.slf4j', module: 'slf4j-api'
}
}

Eclipse: How can I have gradle dependencies deployed to Tomcat

I'm creating a web project using Gradle (buildship) in Eclipse (WTP). I've put the libraries I need as "implementation" dependencies in my build.gradle, however they are not copied to Tomcat when I try to run the project from within Eclipse. When I build the WAR file (with gradle war), however, all the jar files are there.
I can't find anywhere the solution for this. It's beeing awful to manually (and redundantly) copying every jar and its dependency to WEB-INF/libs just to be able to run the app from Eclipse).
I've found a workaround here: https://github.com/eclipse/buildship/issues/496
It's adding this to build.gradle:
eclipse {
wtp {
component {
libConfigurations += [configurations.runtimeClasspath]
}
}
}
With this everything gets properly deployed.
UPDATE!
Gradle 5.3 has just been released and includes a fix for this issue and the hack above is not needed anymore.
The only thing that worked for me was changing
dependencies {
implementation group: 'org.projectlombok', name: 'lombok', version: '1.18.4'
}
too
dependencies {
compile group: 'org.projectlombok', name: 'lombok', version: '1.18.4'
}

Building Gradle EARs from pre-built WARs

I'm using Gradle and want to build an EAR that includes a pre-built WAR file found in a repository. I got things working like this:
dependencies
{
earlib 'PathName:NameOfPreBuiltWar:Version#war'
}
ear
{
libDirName '/'
}
This seems to work perfectly, but isn't the way earlib or libDirName were intended to be used. Is there a better way?
The ear plugin also provides a deploy configuration, so this should be sufficient:
dependencies {
deploy 'PathName:NameOfPreBuiltWar:Version#war'
}

Gradle -- Eclipse classpath still include the jar files that are excluded in the build.gradle file

I'm trying to exclude few jars from the .classpath file which is generated by the gradle eclipse plugin. Though i do the following stuff in my build.gradle to exclude these jars, the classpath still contains these jar files.
configurations {
eclipseExcludedDeps
}
dependencies {
eclipseExcludedDeps group: "javax", name:"javaee-api", version: "${versions.javaee_api}"
eclipseExcludedDeps group: "javax.xml.parsers", name:"jaxp-api", version: "${versions.jaxp_api}"
eclipseExcludedDeps group: "xerces", name:"xmlParserAPIs", version: "${versions.xmlParserAPIs}"
}
eclipse {
wtp {
component {
minusConfigurations << configurations.eclipseExcludedDeps
}
}
}
I have tried all the approaches mentioned in the gradle docs but none of the them works for me.
I'm using gradle version 2.7. To create the classpath i run 'gradle eclipse' command.
Can someone please help me on this.
I'm not a WTP user myself but I think you'll need to configure eclipse.classpath
eclipse {
classpath {
minusConfigurations += [ configurations.eclipseExcludedDeps ]
}
}

You can't change configuration 'providedRuntime' because it is already resolved

I am using Gradle 2.0 with Groovy 2.3.3.
When I run the build below I get the error > You can't change configuration 'providedRuntime' because it is already resolved!
Other posts and release notes suggest that it is to do with +=, however, I'm not using that operator so I am a bit confused.
apply plugin: 'war'
repositories {
mavenCentral()
}
//We don't want transitive dependencies added as we are matching a third-party build
configurations.all {
transitive = false
}
war {
archiveName='gradle.war'
from(configurations.providedRuntime.files) {
into "app-jars"
}
classpath fileTree('webinf-libs') // adds a file-set to the WEB-INF/lib dir.
}
dependencies {
providedRuntime group: 'com.thoughtworks.xstream', name: 'xstream', version: '1.4.2'
}
Changing war configuration to:
war {
archiveName='gradle.war'
from(configurations.providedRuntime) {
into "app-jars"
}
classpath fileTree('webinf-libs') // adds a file-set to the WEB-INF/lib dir.
}
will solve the issue.
The problem occurred because files was called in war configuration block and then dependencies were added to providedRuntime. Since calling files resolves the configuration (and war block is evaluated at configuration phase) it can't be modified later on.
You can also change order of dependencies and war and it will be the same.

Resources