Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7724251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:38:32+00:00 2026-06-01T04:38:32+00:00

I’m having a duplicate files issue with my Gradle build script. My directory structure

  • 0

I’m having a duplicate files issue with my Gradle build script.

My directory structure is the maven standard, plus some extra directories for various build configurations:

/src/main/java
/src/main/resources
/src/main/dev/resources
/src/main/prod/resources

The files from /src/main/resources and /src/main/dev/resources are apparently handled by both the processResources and the war task, and end up in the .war file twice. How can I prevent that from happening without manually excluding each single file in the war configuration?

My entire build.gradle is included below; note buildEnvironment is set to dev by default, but could also be prod.

apply plugin: "sonar"
apply plugin: "war"
apply plugin: "eclipse-wtp"

// ************************************************************************************************
// GENERAL CONFIGURATION
// ************************************************************************************************

sourceCompatibility = 1.6
group = "com.foo"
archivesBaseName = "security"
version = "0.1-SNAPSHOT"

// versions of various components where we need more than one and may want to update often
def springVersion = "3.1.1.RELEASE"
def tomcatVersion = "7.0.25"
def jasperVersion = "4.5.0"

// buildEnvironment is set in gradle.properties and can be overridden with -PbuildEnvironment=... on the command line
println "running in $buildEnvironment mode..."

// set classes output directory to WEB-INF/classes
eclipse.classpath.defaultOutputDir = new File(project.getWebAppDir().getAbsolutePath(), "/WEB-INF/classes")

// ************************************************************************************************
// SOURCE SETS
// ************************************************************************************************

sourceSets {
  // add the resources specific to the build environment
  main.resources.srcDirs += "src/main/$buildEnvironment/resources"
  // add source set for jasper reports
  jasperreports {
    srcDir = file(relativePath('src/main/jasperreports'))
    output.classesDir = file(relativePath('src/main/java/com/foo/bar/security/statistics'))
  }
}

// ************************************************************************************************
// PLUGINS
// ************************************************************************************************

buildscript {
  repositories {
    add(new org.apache.ivy.plugins.resolver.URLResolver()) {
      name = 'GitHub'
      addArtifactPattern 'http://cloud.github.com/downloads/[organisation]/[module]/[module]-[revision].[ext]'
    }
  }

  dependencies { classpath 'bmuschko:gradle-tomcat-plugin:0.9' }
}

apply plugin: "tomcat"

// ************************************************************************************************
// PLUGIN CONFIGURATION
// ************************************************************************************************

// configure eclipse .project/.classpath generator
eclipse {
  project { natures 'com.springsource.sts.gradle.core.nature' }
  wtp { component { contextPath = "/security" } }
}

configurations {
  // make sure we don't get dependencies we don't want
  all*.exclude group: "net.sf.ehcache", module: "ehcache-terracotta"
  all*.exclude group: "bouncycastle", module: "bcmail-jdk14"
  all*.exclude group: "bouncycastle", module: "bcprov-jdk14"
  all*.exclude group: "bouncycastle", module: "bctsp-jdk14"

  // wtp needs a special invitation for some reason
  eclipseWtpComponent {
    exclude group: "net.sf.ehcache", module: "ehcache-terracotta"
  }

  jasperreports { transitive = true }
}

// maven repositories
repositories {
  maven { url "http://maven.springframework.org/milestone/" }
  mavenCentral()
}

// sonar configuration
sonar {
  server { url = "http://xxx" }
  database {
    url = "jdbc:mysql://xxx"
    driverClassName = "com.mysql.jdbc.Driver"
    username = "xxx"
    password = "xxx"
  }
  project { key = "foo.bar:security" }
}

war {
  // set war output file name
  archiveName = "security.war"
  // make sure no duplicate processing of files takes place
  excludes += [
    "**/database.properties",
    "**/logback.xml",
    "**/rebel.xml",
    "**/upload.properties",
    "**/ValidationMessages.properties"
  ]
}

tomcatRun { contextPath = "/security" }

// ************************************************************************************************
// DEPENDENCIES
// ************************************************************************************************

dependencies {

  // exclusions for jasperreports, which tries to load old versions of stuff
  compile("net.sf.jasperreports:jasperreports:$jasperVersion") {
    exclude module: "jfreechart"
    exclude module: "jcommon"
  }

  // exclusions for ehcache, we don't want their enterprise cache
  compile("net.sf.ehcache:ehcache:2.5.1") {
    exclude group: "net.sf.ehcache", module: "ehcache-terracotta"
  }

  // compile and runtime dependencies
  compile   "org.springframework:spring-webmvc:$springVersion",
      "org.springframework:spring-orm:$springVersion",
      "org.springframework:spring-aspects:$springVersion",
      "org.springframework.mobile:spring-mobile-device:1.0.0.RC1",
      "org.jfree:jfreechart:1.0.14",
      "org.apache.tiles:tiles-jsp:2.2.2",
      "c3p0:c3p0-oracle-thin-extras:0.9.1.2",
      "org.mybatis:mybatis-spring:1.0.2",
      "org.aspectj:aspectjrt:1.6.12",
      "org.aspectj:aspectjweaver:1.6.12",
      "org.codehaus.jackson:jackson-mapper-asl:1.9.4",
      "ch.qos.logback:logback-classic:1.0.0",
      "org.slf4j:jcl-over-slf4j:1.6.4",
      "org.slf4j:log4j-over-slf4j:1.6.4",
      "org.slf4j:jul-to-slf4j:1.6.4",
      "org.hibernate:hibernate-validator:4.2.0.Final",
      "com.google.guava:guava:11.0.1",
      "commons-dbutils:commons-dbutils:1.4",
      "commons-fileupload:commons-fileupload:1.2.2",
      "commons-io:commons-io:2.1",
      "commons-lang:commons-lang:2.6",
      "org.bouncycastle:bcprov-jdk16:1.46",
      "org.quartz-scheduler:quartz:2.1.3",
      "jdom:jdom:1.1",
      "cglib:cglib:2.2.2",
      "org.jasypt:jasypt:1.9.0",
      "com.sun.mail:smtp:1.4.4",
      "com.sun.mail:mailapi:1.4.4",
      "xalan:xalan:2.7.1",
      "org.jdom:saxpath:1.0-FCS"

  runtime "javax.servlet:jstl:1.2"

  // for compiling jasper reports
  jasperreports "net.sf.jasperreports:jasperreports:$jasperVersion",
      "org.codehaus.groovy:groovy-all:1.8.6"

}

// dependencies for each tomcat version, which are in different packages for 6.x and 7.x, sigh
println "adding dependencies for Tomcat $tomcatVersion"
if (tomcatVersion.startsWith("6")) {
  dependencies.add("providedCompile", "org.apache.tomcat:catalina:$tomcatVersion")
  dependencies.add("tomcat", "org.apache.tomcat:catalina:$tomcatVersion")
  dependencies.add("tomcat", "org.apache.tomcat:coyote:$tomcatVersion")
  dependencies.add("tomcat", "org.apache.tomcat:jasper:$tomcatVersion")
} else if (tomcatVersion.startsWith("7")) {
  dependencies.add("providedCompile", "org.apache.tomcat:tomcat-catalina:$tomcatVersion")
  dependencies.add("tomcat", "org.apache.tomcat:tomcat-catalina:$tomcatVersion")
  dependencies.add("tomcat", "org.apache.tomcat:tomcat-coyote:$tomcatVersion")
  dependencies.add("tomcat", "org.apache.tomcat:tomcat-jasper:$tomcatVersion")
}

// ************************************************************************************************
// JASPER REPORTS
// ************************************************************************************************

task jasperReports(overwrite: true) << {
  ant {
    taskdef(name: 'jrc',
        classname: 'net.sf.jasperreports.ant.JRAntCompileTask',
        classpath: configurations.jasperreports.asPath)
    mkdir(dir:sourceSets.jasperreports.output.classesDir)
    jrc(srcdir: sourceSets.jasperreports.srcDir, destdir: sourceSets.jasperreports.output.classesDir) {
      include(name:'**/*.jrxml')
      classpath {
        pathElement(path: configurations.jasperreports.asPath)
      }
    }
  }
}

task cleanJasperReports(overwrite: true) << {
  ant.delete() {
    fileset(dir:sourceSets.jasperreports.output.classesDir, includes: "*.jasper")
  }
}

compileJava.dependsOn jasperReports
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T04:38:33+00:00Added an answer on June 1, 2026 at 4:38 am

    I have not tested your configuration here, but I think it’s because you are adding main.resources.srcDirs += "src/main/$buildEnvironment/resources" to sourceSets. By adding this you have now the following sourceSets if buildEnvironment = 'dev':

    • src/main/java
    • src/main/resources
    • src/main/dev/resources

    This means if you have a resource called myfile.txt in both src/main/resources and src/main/dev/resources you would get the following files:

    • WEB-INF/classes/myfile.txt
    • WEB-INF/classes/dev/myfile.txt

    To fix this you could just move your dev/prod resources outside of src/main, ex. like this:

    • src/main/java
    • src/main/resources
    • src/dev/resources
    • src/prod/resources

    And use the following sourceSet instead:

    main.resources.srcDirs += "src/$buildEnvironment/resources"
    

    Then all dev/prod resources will override the resources in src/main/resources.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have thousands of HTML files to process using Groovy/Java and I need to
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have some data like this: 1 2 3 4 5 9 2 6

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.