Custom Plugin: add extension parameters to applied plugin

I am new to writing plugins …
I am writing Custom plugin (say: PLUGIN1) in Java. The Custom plugin applies another plugin(say: PLUGIN2) using : project.getPlugins.apply("…").
PLUGIN2 has 2 to 3 extensions and I want to customize those values in the extensions for my PLUGIN1.
plugin2ext { outputdir=" "; }
in PLUGIN1, I want to override it with plugin2ext.outputdir = "some value"
Any suggestions in using API’s ? do I need to create extension like the code below and set parameters or is there any other way ?
PLUGIN2Ext ext = (PLUGIN2Ext) project.getExtensions.getByName(…);
ext.outputdir = “some value” ?