Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MBUILDCACHE-22] added flag to force rebuild per project or globally #24

Merged
merged 6 commits into from
Oct 16, 2022

Conversation

eltsovalex
Copy link
Contributor

@eltsovalex eltsovalex commented Aug 26, 2022

added possibility to skip generated sources restore on per-project level
added some logging

Following this checklist to help us incorporate your
contribution quickly and easily:

  • Make sure there is a JIRA issue filed
    for the change (usually before you start working on it). Trivial changes like typos do not
    require a JIRA issue. Your pull request should address just this issue, without
    pulling in other changes.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Format the pull request title like [MNG-XXX] - Fixes bug in ApproximateQuantiles,
    where you replace MNG-XXX with the appropriate JIRA issue. Best practice
    is to use the JIRA issue title in the pull request title and in the first line of the
    commit message.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Run mvn clean verify to make sure basic checks pass. A more thorough check will
    be performed on your pull request automatically.
  • You have run the Core IT successfully.

If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.

To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.

added possibility to skip generated sources restore on per-project level
added some logging
@eltsovalex
Copy link
Contributor Author

eltsovalex commented Aug 26, 2022

(https://issues.apache.org/jira/browse/MBUILDCACHE-22)
(https://issues.apache.org/jira/browse/MBUILDCACHE-23)

Basically this PR is about adding 2 new features which are required to use this extension in yet another complex multi-module project in Deutsche Bank

  1. ability to skip cache lookup for a particular module or whole project (required to get some modules always built e.g. via a profile - e.g. I have some additional artifacts published by CI). Alternatively it allows an easy "force" rebuild of a whole project
    The difference with not using cache is that results are put into cache, just current matching versions are not taken from caches

  2. ability to disable generated source restoration on a per-module level. This is required to overcome issues with some weird Maven plugins which go nuts when cached generated sources are present and produce incorrect build result

@maximilian-novikov-db
Copy link
Contributor

@@ -87,6 +87,16 @@ public class CacheConfigImpl implements org.apache.maven.buildcache.xml.CacheCon
public static final String RESTORE_GENERATED_SOURCES_PROPERTY_NAME = "maven.build.cache.restoreGeneratedSources";
public static final String ALWAYS_RUN_PLUGINS = "maven.build.cache.alwaysRunPlugins";

/**
* Flag to control if we should skip lookup for cached artifacts globally r for a particular project even if
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a typo

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@eltsovalex eltsovalex changed the title added possibility to skip cache lookup per project or globally [MBUILDCACHE-22] added possibility to skip cache lookup per project or globally Aug 30, 2022
@hboutemy
Copy link
Member

hboutemy commented Sep 5, 2022

is it possible to add a note in documentation about this feature and how to use it, please?
https://github.com/apache/maven-build-cache-extension/tree/master/src/site/markdown

@hboutemy hboutemy requested a review from gnodet September 5, 2022 06:42
Copy link
Contributor

@gnodet gnodet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, please fix the typo in the javadoc in CacheConfigImpl.java and document its usage in the documentation.

@eltsovalex
Copy link
Contributor Author

Typos fixed in javadoc + new parameters described in documentation

{
result = cacheController.findCachedBuild( session, project, mojoExecutions );
result = cacheController.findCachedBuild( session, project, mojoExecutions, skipCacheLookup );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right now cache could be accessed when no initialized (it seems). not sure if it could cause any issues but in terms of naming and contract clarity it is not so clear . skipCache should work better

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AlexanderAshitkin renamed to skipCache

@@ -96,6 +97,7 @@ public void execute( List<MojoExecution> mojoExecutions,
// execute clean bound goals before restoring to not interfere/slowdown clean
CacheState cacheState = DISABLED;
CacheResult result = CacheResult.empty();
boolean skipCacheLookup = cacheConfig.isSkipLookup() || MavenProjectInput.shouldSkipCacheLookup( project );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

regarding the naming - lets call it skipCache. Gradle has similar parameter to force rebuild named --no-build-cache.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

result = localBuild;
}
else
// remote build first
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please change this comment to something like Central repository build first
remote and local notation is confusing here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not my comment - just part of code by @gnodet that I've moved inside a block

@@ -123,10 +127,16 @@ private List<Plugin> normalizePlugins( List<Plugin> plugins )
{
Plugin copy = plugin.clone();
List<String> excludeProperties = cacheConfig.getEffectivePomExcludeProperties( copy );
removeBlacklistedAttributes( copy.getConfiguration(), excludeProperties );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is it now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AlexanderAshitkin the code is still there - just after debug output

filteredOutPaths.add( Paths.get( properties.getProperty( propertyName ) ) );
}
}
CacheUtils.debugPrintCollection( LOGGER, filteredOutPaths,
"List of excluded paths (checked either by fileName or by startsWith prefix)",
"Pah entry" );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo. Pah entry is a medical term likely ¯_(ツ)_/¯

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -32,6 +32,7 @@ This documents contains various configuration parameters supported by cache engi
| `-Dmaven.build.cache.lazyRestore=(true/false)` | Restore artifacts from remote cache lazily | Performance optimization |
| `-Dmaven.build.cache.restoreGeneratedSources=(true/false)` | Do not restore generated sources and directly attached files | Performance optimization |
| `-Dmaven.build.cache.alwaysRunPlugins=<list of plugins>` | Comma seprated list of plugins to always run regardless of cache state. An example: `maven-deploy-plugin:*,maven-install-plugin:install` | Remote cache setup/tuning/troubleshooting |
| `-Dmaven.build.cache.skipLookup=(true/false)` | Skip looking up artifacts in caches. Does not affect writing artifacts to caches, disables only reading when set to `true` | May be used to trigger a forced rebuild when maching artifatcs do exist in caches|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From command line and pom perspective -Dorg.maven.build.cache.rerun is more expressive because it assumes that cache will be invalidated and rebuilt. Another option is which is also look better is -Dorg.maven.build.cache.skipCache just seems more expressive to me

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AlexanderAshitkin renamed to -Dorg.maven.build.cache.skipCache

LOGGER.debug( "Adding an excludePath from property '{}', values is '{}', path is '{}' ",
propertyName, propertyValue, path );
}

filteredOutPaths.add( Paths.get( properties.getProperty( propertyName ) ) );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no longer need this line, to be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AlexanderAshitkin thanks, fixed

@@ -819,4 +833,22 @@ public int compare( Path f1, Path f2 )
}
}

public static boolean shouldSkipCacheLookup( MavenProject project )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

skipCache or isSkipCache will be better

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AlexanderAshitkin
Copy link
Contributor

I would rename this pr into "flag to force rebuild" which better describes new functionality

@@ -32,7 +32,7 @@ This documents contains various configuration parameters supported by cache engi
| `-Dmaven.build.cache.lazyRestore=(true/false)` | Restore artifacts from remote cache lazily | Performance optimization |
| `-Dmaven.build.cache.restoreGeneratedSources=(true/false)` | Do not restore generated sources and directly attached files | Performance optimization |
| `-Dmaven.build.cache.alwaysRunPlugins=<list of plugins>` | Comma seprated list of plugins to always run regardless of cache state. An example: `maven-deploy-plugin:*,maven-install-plugin:install` | Remote cache setup/tuning/troubleshooting |
| `-Dmaven.build.cache.skipLookup=(true/false)` | Skip looking up artifacts in caches. Does not affect writing artifacts to caches, disables only reading when set to `true` | May be used to trigger a forced rebuild when maching artifatcs do exist in caches|
| `-Dmaven.build.cache.skip=(true/false)` | Skip looking up artifacts in caches. Does not affect writing artifacts to caches, disables only reading when set to `true` | May be used to trigger a forced rebuild when maching artifatcs do exist in caches|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small typo. maching -> matching

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AlexanderAshitkin - thx, fixed

@eltsovalex eltsovalex changed the title [MBUILDCACHE-22] added possibility to skip cache lookup per project or globally [MBUILDCACHE-22] added flag to force rebuild per project or globally Sep 15, 2022
@maximilian-novikov-db
Copy link
Contributor

@gnodet please merge

@gnodet gnodet merged commit dd09baa into apache:master Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants