Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

346
Views
exclude the configuration file (.xml and package) from dependency jar in gradle spring project

In my spring project we are using web dependency contains a configuration applicationContext.xml and security-config.xml. I have to change on both of them in my application how can I achieve this.

I'm expecting like this

compile (librariesdependencyname) {
        exclude ('applicationContext.xml')
        exclude ('common-security-config.xml')
    }
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

If your team handling the jar. Just ask them to creating new version and without this configuration and resource files

OR

You can modify the context loader loaction and patter like below

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath*:applicationContext.xml,classpath*:/**/*-config.xml</param-value>
    </context-param>
over 4 years ago · Santiago Trujillo Report

0

More information about the project setup will help with more accurate suggestions. There can be multiple way to achieve.

Assuming you have following

  1. Library has mentioned xml files
  2. We want the code not the configurations

As @Araf mentioned, we can request the team to update the library and change the configuration

  1. Restructure the code to provide Autoconfigurations files this way consumer of library can choose to load the configurations through autoload or not
  2. Define your own xml files to load so that it will not load library configurations

One way to achieve AutoConfiguration mechanism mentioned at https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.developing-auto-configuration or as it is your own project you can try multi module project https://www.baeldung.com/spring-boot-multiple-modules

Choosing which package to load or exclude, we can use @ComponentScan https://www.baeldung.com/spring-component-scanning.

XML version of annotations should be available, I personally prefer the annotations as it will use code as configurations.

over 4 years ago · Santiago Trujillo Report

0

You can add a custom task in gradle and instead of adding your jar compile "dependency. Define it as "something" dependency. Access it object using configurations."something" . Refer example below

librariesdependency "<<package-librariesdependencyname>>"

jar.dependsOn 'customJar'

task customJar (type: Jar) {
archiveName = 'your-output.jar'
from zipTree(configurations.librariesdependency.singleFile)
exclude 'applicationContext.xml'
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!