maven-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Richard Sand" <rs...@idfconnect.com>
Subject RE: how to properly propagate plugin results into subsequent phases
Date Thu, 18 Jul 2013 06:01:35 GMT
Hi all,

Can someone please help me with the proper technique when manipulating the
dependent artifacts within a custom plugin.

To put it simply, my plug-in may take in multiple source, say
/target/classes plus for example 3 dependent compile-time artifacts. It'll
take these in - classes, plus 3 dependent libraries, and run them through
the processor. It'll save the results as a jar file called
${projectname}-small.jar

Sometimes, we're now done. But more often than not, there are more stages to
be processed. For example, maven-war-plugin needs to make a war package with
the input artifacts. So, what I want to do is include the obfuscated jar as
a library in the WEB-INF/lib of the war, but I want to skip the classes and
other 3 dependent artifacts that went into the optimizer. What is the best
way to do this, in keeping with maven architecture?

Appreciate any help!

-Richard





-----Original Message-----
From: Richard Sand [mailto:rsand@idfconnect.com] 
Sent: Saturday, July 13, 2013 11:36 AM
To: 'Maven Users List'
Subject: how to properly propagate plugin results into subsequent phases

Hi all,

I'm having trouble getting the output jar from this obfuscation plug-in I'm
writing to be processed properly by subsequent plugins (e.g.
maven-war-plugin and maven-install-plugin). Can someone with more savvy with
the Maven 3.0 API give some advice on where I'm going wrong?

The obfuscator takes the class files from ${project.build.outputDirectory}
(e.g. ./target/classes), plus optionally some other jars from the project
dependencies, and creates an obfuscated jar file such as
${project.build.directory}/${project.build.finalName}-obfuscated.jar.

What I want to do is add this new jar, e.g.
"myproject-1.0.0-obfuscated.jar", into subsequent phases such as
maven-war-plugin (to be included in the output artifact's WEB-INF/lib
folder) while excluding the input (e.g. ignore the ./target/classes and the
dependent jars which were included in the obfuscation).

To add the obfuscated jar into subsequent phases, I tried to include it by
using "mavenProjectHelper.attachArtifact" - but this gave me a very strange
behavior - when the install-plugin executed, it took the war file created by
maven-war-plugin and installed that over top of my last dependent jar! In
other words, it took myapp-1.0.0.war and myapp-1.0.0.pom and put them into
the repository as somedependency.jar and somedependency.pom. Very strange -
and although I'm sure I'm doing something wrong, that outcome feels like a
bug to me anyway. At least something that isn't idiot-proof! But this is
where I am least confident in my approach - can someone advise if I'm doing
this with the wrong technique?

To prevent the dependent jars which were obfuscated from being included in
subsequent phases, I'm finding each dependency from the project artifact
map, and then doing artifact.setScope(Artifact.SCOPE_PROVIDED) and
mavenProject.setArtifact(artifact) to put it back into the project. Any
comment on this technique?

Lastly, I'm not sure how to exclude the "primary" output from the compile
phase - e.g. if I compile ./target/classes, or if my plugin is running after
the packaging phase and I've got ./target/myproject-1.0.0.jar, how do I
exclude these after I successfully include
./target/myproject-1.0.0-obfuscated.jar?

Appreciate any help here. Thanks!

-Richard




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Mime
View raw message