Android Development
Build Errors
Gradle
META-INF
License Files

More than one file was found with OS independent path 'META-INF/LICENSE'

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

When developing software applications, particularly in Java, developers or build tools often encounter a warning or error message stating that "More than one file was found with OS independent path 'META-INF/LICENSE'." Understanding the origin and resolution of such issues is crucial for seamless project builds. This article provides an in-depth look at this issue, its implications, and how to resolve it.

Background: What is on 'META-INF/LICENSE'?

In a typical Java project, libraries and dependencies can include metadata folders that follow the Java Archive (JAR) conventions. The META-INF directory usually contains configuration and metadata files such as MANIFEST.MF and various licenses (e.g., LICENSE, NOTICE). These files aren't unique to any single dependency and may appear in multiple external libraries.

The LICENSE file holds the licensing terms under which the library is distributed. When different libraries contain the same file name within their META-INF directories, it can cause conflicts during the build process, especially when tools like Gradle or Maven attempt to package your application.

How the Issue Arises

Collision Explanation

When building a project, tools like Gradle create a final JAR or an AAR (for Android projects). During this process, it’s common for these tools to merge resources from different libraries or modules. If two or more dependencies include a file named META-INF/LICENSE, this results in a path collision, as the build system attempts to place all these files under the same directory in the final artifact.

Impact on Build Process

Such file clashes result in warnings or errors depending on the build tool's configuration. This issue doesn't directly affect the runtime but could prevent successful builds, thereby blocking development and deployment.

Example Scenarios

  1. Using Multiple Libraries: If you include two libraries that both have their licenses stored at META-INF/LICENSE, a conflict occurs.
    • Example: Including AWS SDK and Apache Commons IO in your project where both have their license files in META-INF/LICENSE.
  2. Multi-Module Projects: Large projects structured as multiple modules might inadvertently declare libraries that conflict.

Resolving the Conflict

Strategy 1: Merging Resources

You can configure your build tool to allow merging these resources, although the license information may be concatenated or overridden.

  • Gradle: Use the packagingOptions directive to exclude or merge files. For example:
groovy
1  android {
2      packagingOptions {
3          exclude 'META-INF/LICENSE'
4      }
5  }

Strategy 2: Excluding Redundant Files

If license files are not needed in your final build, you can exclude them. This is particularly common in production builds.

  • Gradle:
groovy
1  android {
2      packagingOptions {
3          pickFirst 'META-INF/LICENSE' // This will pick the first LICENSE encountered
4      }
5  }
  • Maven: Maven projects can handle such conflicts via the Maven Shade Plugin, using its filters functionality to exclude these files.

Strategy 3: Maintaining Licenses Separately

Extract and preserve license information manually, ensuring that your application is compliant with all necessary licenses.

Summary Table

ItemDescription
LocationMETA-INF/LICENSE
Collision CauseMultiple dependencies contain the same file name
Tools AffectedBuild tools like Gradle, Maven
Common SolutionsExclude, pick first, or merge LICENSE files
Impact on BuildsWarnings, errors preventing successful builds
Practical ExampleAWS SDK and Apache Commons IO concurrently added

Additional Considerations

  • Compliance: Simply excluding license files doesn't absolve any legal requirements to meet license conditions of included libraries. Ensure compliance by manually reviewing and documenting licenses.
  • Alternative File Locations: Some developers navigate this issue by moving these metadata files to other directory locations or maintaining them elsewhere. However, this isn't a standard and can make maintenance complex.
  • Continuous Integration (CI): In a CI/CD pipeline, failing builds due to this error can halt deployment, so it's crucial to maintain a clean build configuration script that handles these conditions gracefully.

This error or warning regarding META-INF/LICENSE is common in multi-dependency Java projects. While it primarily arises due to collisions in metadata, resolving it enables a smoother build process and ensures project integrity. Understanding the tools and methods to mitigate these issues will help developers maintain efficient and effective workflows.


Related reading
Course
Intermediate
27 lessons
14 hours
OOD Fundamentals

Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.