apache / apache/maven-build-cache-extension

[MBUILDCACHE-54] Project scoped dependency of a module contributes so the hash of the module itself breaking cache logic

Open
#262 6 comments 1 reaction 0 assignees View on GitHub
bug priority:major
Dominant language
Java
Stars
163
Forks
77
Avg merge
1d 2h
Merged PRs (30d)
4

Description

**[LoneDev](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=JIRAUSER299881)** opened **[MBUILDCACHE-54](https://issues.apache.org/jira/browse/MBUILDCACHE-54?redirect=false)** and commented

I have a maven project structured this way:
* Core
* module1
* module2
* module3

 

Each submodule has Core as dependency, because they need to access some stuff in the Core module.

```java

dev.lone
Core
1.0
provided

```

The issue is that when I edit the Core the hash of the modules changes too because their hash is made of their dependencies too.

What I'd expect is the hash of the submodules (module1, module2, module3) won't get modified if the dependency Core has some files edited.
I'd expect only the hash of the Core dependency change triggering the build for only the Core module.
Right now the build process is triggered for every module if a single file of the Core is edited because its hash changes.

This makes the caching system useless in my project.

I think a solution would be to correctly exclude a dependency from the hash of the module if the dependency is a module of the current project.
I thought this already was the current logic by reading your code, but seems somehow it's not.

 

I found that out by enabling debug using `-X` maven argument and noticed that the dependency hash was changing for one of the two dependencies in the log, but the others remained the same.

Example:

```java
[DEBUG] Hash calculated, item: file, hash: aed7a7726072b1f2
[DEBUG] Hash calculated, item: file, hash: af38807c7b6d4d82
[DEBUG] Hash calculated, item: file, hash: 7b2b9b026b4247b0
[DEBUG] Hash calculated, item: file, hash: 5d3e80058614177e
[DEBUG] Hash calculated, item: file, hash: f656e74567358a0e
[DEBUG] Hash calculated, item: file, hash: 24836dacb4dec612
[DEBUG] Hash calculated, item: dependency, hash: ceaa4062fafc0392
[DEBUG] Hash calculated, item: dependency, hash: 933c5b7ec84b6afa ### <---- this
```

This is strange since checking your code it should automatically exclude a dependency from the module hash if the dependency itself is a module of the project, right?

Here the relevant code I found in your repo:

calculateChecksum()
https://github.com/apache/maven-build-cache-extension/blob/241ebce428e6ee4f9d2c8ad43e65d44d9eaf947e/src/main/java/org/apache/maven/buildcache/checksum/MavenProjectInput.java#L206

call to getMutableDependencies() 
https://github.com/apache/maven-build-cache-extension/blob/241ebce428e6ee4f9d2c8ad43e65d44d9eaf947e/src/main/java/org/apache/maven/buildcache/checksum/MavenProjectInput.java#L211

getMutableDependencies()
https://github.com/apache/maven-build-cache-extension/blob/241ebce428e6ee4f9d2c8ad43e65d44d9eaf947e/src/main/java/org/apache/maven/buildcache/checksum/MavenProjectInput.java#L644

 

Call to normalizedModel()
https://github.com/apache/maven-build-cache-extension/blob/241ebce428e6ee4f9d2c8ad43e65d44d9eaf947e/src/main/java/org/apache/maven/buildcache/checksum/MavenProjectInput.java#L209

 

normalizedModel() and call to normalizedModelInner()
https://github.com/apache/maven-build-cache-extension/blob/241ebce428e6ee4f9d2c8ad43e65d44d9eaf947e/src/main/java/org/apache/maven/buildcache/DefaultNormalizedModelProvider.java#L62

 

normalizedModelInner() and call to normalizePlugins()
https://github.com/apache/maven-build-cache-extension/blob/241ebce428e6ee4f9d2c8ad43e65d44d9eaf947e/src/main/java/org/apache/maven/buildcache/DefaultNormalizedModelProvider.java#L95

 

normalizePlugins() and call to isPartOfMultiModule()
This is what I think could be changed to fix the issue. Basically call `return;` instead of `copy.setVersion(NORMALIZED_VERSION);`
https://github.com/apache/maven-build-cache-extension/blob/241ebce428e6ee4f9d2c8ad43e65d44d9eaf947e/src/main/java/org/apache/maven/buildcache/DefaultNormalizedModelProvider.java#L113

 

isPartOfMultiModule()

https://github.com/apache/maven-build-cache-extension/blob/241ebce428e6ee4f9d2c8ad43e65d44d9eaf947e/src/main/java/org/apache/maven/buildcache/DefaultMultiModuleSupport.java#L85

Thanks!

 

---

**Affects:** 1.0.0

**Remote Links:**
- [GitHub Pull Request #69
](https://github.com/apache/maven-build-cache-extension/pull/69)

0 votes, 5 watchers

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with MavenProjectInput.calculateChecksum() and its getMutableDependencies() and normalizedModel() calls. Read DefaultNormalizedModelProvider.normalizePlugins() and DefaultMultiModuleSupport.isPartOfMultiModule(), then reproduce the dependency-hash change with a multi-module Maven project using -X. Done means editing Core no longer changes module1, module2, or module3 hashes while Core's hash still changes.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.