@@ -57,6 +57,8 @@ public abstract class JavaModulePackagingExtension {
5757 private static final String INTERNAL = "internal" ;
5858 private static final String JPACKAGE = "jpackage" ;
5959
60+ private final Project project ;
61+
6062 public abstract Property <String > getApplicationName ();
6163
6264 public abstract Property <String > getApplicationVersion ();
@@ -86,7 +88,9 @@ public abstract class JavaModulePackagingExtension {
8688 protected abstract ObjectFactory getObjects ();
8789
8890 @ Inject
89- protected abstract Project getProject ();
91+ public JavaModulePackagingExtension (Project project ) {
92+ this .project = project ;
93+ }
9094
9195 /**
9296 * Retrieve the target with the given 'label'. If the target does not yet exist, it will be created.
@@ -130,8 +134,8 @@ public void targetsWithOs(String operatingSystem, Action<? super Target> action)
130134 */
131135 @ SuppressWarnings ("unused" )
132136 public Target primaryTarget (Target target ) {
133- SourceSetContainer sourceSets = getProject () .getExtensions ().getByType (SourceSetContainer .class );
134- ConfigurationContainer configurations = getProject () .getConfigurations ();
137+ SourceSetContainer sourceSets = project .getExtensions ().getByType (SourceSetContainer .class );
138+ ConfigurationContainer configurations = project .getConfigurations ();
135139
136140 sourceSets .all (sourceSet -> {
137141 // Use this target for target-independent classpaths to make some decision
@@ -165,14 +169,13 @@ public TestSuite multiTargetTestSuite(TestSuite testSuite) {
165169 task .getInputs ().property ("operatingSystem" , target .getOperatingSystem ());
166170 task .getInputs ().property ("architecture" , target .getArchitecture ());
167171
168- ConfigurationContainer configurations = getProject () .getConfigurations ();
172+ ConfigurationContainer configurations = project .getConfigurations ();
169173 task .setClasspath (configurations
170174 .getByName (target .getName ()
171175 + capitalize (suite .getSources ().getRuntimeClasspathConfigurationName ()))
172176 .plus (getObjects ()
173177 .fileCollection ()
174- .from (getProject ()
175- .getTasks ()
178+ .from (project .getTasks ()
176179 .named (suite .getSources ().getJarTaskName ()))));
177180 task .doFirst (new ValidateHostSystemAction ());
178181 })));
@@ -193,8 +196,8 @@ private void newTarget(Target target) {
193196 return Collections .emptyList ();
194197 }));
195198
196- ConfigurationContainer configurations = getProject () .getConfigurations ();
197- SourceSetContainer sourceSets = getProject () .getExtensions ().getByType (SourceSetContainer .class );
199+ ConfigurationContainer configurations = project .getConfigurations ();
200+ SourceSetContainer sourceSets = project .getExtensions ().getByType (SourceSetContainer .class );
198201
199202 sourceSets .all (sourceSet -> {
200203 Configuration internal = maybeCreateInternalConfiguration ();
@@ -222,8 +225,7 @@ private void newTarget(Target target) {
222225 });
223226
224227 if (SourceSet .isMain (sourceSet )) {
225- getProject ()
226- .getPlugins ()
228+ project .getPlugins ()
227229 .withType (
228230 ApplicationPlugin .class ,
229231 p -> registerTargetSpecificTasks (target , sourceSet .getJarTaskName (), runtimeClasspath ));
@@ -267,10 +269,10 @@ private void configureTargetAttributes(Configuration resolvable, Target target)
267269 }
268270
269271 private void registerTargetSpecificTasks (Target target , String applicationJarTask , Configuration runtimeClasspath ) {
270- TaskContainer tasks = getProject () .getTasks ();
272+ TaskContainer tasks = project .getTasks ();
271273
272- JavaPluginExtension java = getProject () .getExtensions ().getByType (JavaPluginExtension .class );
273- JavaApplication application = getProject () .getExtensions ().getByType (JavaApplication .class );
274+ JavaPluginExtension java = project .getExtensions ().getByType (JavaPluginExtension .class );
275+ JavaApplication application = project .getExtensions ().getByType (JavaApplication .class );
274276
275277 TaskProvider <Jpackage > jpackage = tasks .register (JPACKAGE + capitalize (target .getName ()), Jpackage .class , t -> {
276278 t .getJavaInstallation ()
@@ -302,9 +304,9 @@ private void registerTargetSpecificTasks(Target target, String applicationJarTas
302304 t .getVerbose ().convention (getVerbose ());
303305
304306 t .getDestination ()
305- .convention (getProject () .getLayout ().getBuildDirectory ().dir ("packages/" + target .getName ()));
307+ .convention (project .getLayout ().getBuildDirectory ().dir ("packages/" + target .getName ()));
306308 t .getTempDirectory ()
307- .convention (getProject () .getLayout ().getBuildDirectory ().dir ("tmp/jpackage/" + target .getName ()));
309+ .convention (project .getLayout ().getBuildDirectory ().dir ("tmp/jpackage/" + target .getName ()));
308310 });
309311
310312 tasks .register ("run" + capitalize (target .getName ()), JavaExec .class , t -> {
@@ -339,11 +341,11 @@ private void maybeAddJpackageLifecycleTask(
339341 }
340342
341343 private Configuration maybeCreateInternalConfiguration () {
342- Configuration internal = getProject () .getConfigurations ().findByName (INTERNAL );
344+ Configuration internal = project .getConfigurations ().findByName (INTERNAL );
343345 if (internal != null ) {
344346 return internal ;
345347 }
346- return getProject () .getConfigurations ().create (INTERNAL , i -> {
348+ return project .getConfigurations ().create (INTERNAL , i -> {
347349 i .setCanBeResolved (false );
348350 i .setCanBeConsumed (false );
349351 });
0 commit comments