2121import com .google .cloud .tools .jib .image .json .BuildableManifestTemplate ;
2222import com .google .common .base .Preconditions ;
2323import com .google .common .base .Strings ;
24+ import java .nio .file .Path ;
2425import java .util .Collections ;
2526import java .util .List ;
2627import javax .annotation .Nullable ;
@@ -66,11 +67,16 @@ public class JibExtension {
6667 private static final boolean DEFAULT_USE_ONLY_PROJECT_CACHE = false ;
6768 private static final boolean DEFAULT_ALLOW_INSECURE_REGISTIRIES = false ;
6869
70+ private static Path resolveDefaultExtraDirectory (Path projectDirectory ) {
71+ return projectDirectory .resolve ("src" ).resolve ("main" ).resolve ("jib" );
72+ }
73+
6974 private final ImageConfiguration from ;
7075 private final ImageConfiguration to ;
7176 private final ContainerParameters container ;
7277 private final Property <Boolean > useOnlyProjectCache ;
7378 private final Property <Boolean > allowInsecureRegistries ;
79+ private final Property <Path > extraDirectory ;
7480
7581 // TODO: Deprecated parameters; remove these 4
7682 private final ListProperty <String > jvmFlags ;
@@ -92,13 +98,15 @@ public JibExtension(Project project) {
9298
9399 useOnlyProjectCache = objectFactory .property (Boolean .class );
94100 allowInsecureRegistries = objectFactory .property (Boolean .class );
101+ extraDirectory = objectFactory .property (Path .class );
95102
96103 // Sets defaults.
97104 from .setImage (DEFAULT_FROM_IMAGE );
98105 jvmFlags .set (Collections .emptyList ());
99106 args .set (Collections .emptyList ());
100107 useOnlyProjectCache .set (DEFAULT_USE_ONLY_PROJECT_CACHE );
101108 allowInsecureRegistries .set (DEFAULT_ALLOW_INSECURE_REGISTIRIES );
109+ extraDirectory .set (resolveDefaultExtraDirectory (project .getProjectDir ().toPath ()));
102110 }
103111
104112 /**
@@ -176,6 +184,10 @@ public void setAllowInsecureRegistries(boolean allowInsecureRegistries) {
176184 this .allowInsecureRegistries .set (allowInsecureRegistries );
177185 }
178186
187+ public void setExtraDirectory (Path extraDirectory ) {
188+ this .extraDirectory .set (extraDirectory );
189+ }
190+
179191 @ Internal
180192 String getBaseImage () {
181193 return Preconditions .checkNotNull (from .getImage ());
@@ -251,4 +263,10 @@ boolean getUseOnlyProjectCache() {
251263 boolean getAllowInsecureRegistries () {
252264 return allowInsecureRegistries .get ();
253265 }
266+
267+ @ Input
268+ @ Optional
269+ Path getExtraDirectory () {
270+ return extraDirectory .get ();
271+ }
254272}
0 commit comments