Note that there are some explanatory texts on larger screens.

plurals
  1. POMaven: compile aspectj project containing Java 1.6 source
    primarykey
    data
    text
    <h2>Primary Question</h2> <p>What I want to do is fairly easy. Or so you would think. However, nothing is working properly.</p> <p><strong>Requirement:</strong> Using maven, compile Java 1.6 project using AspectJ compiler.</p> <p><strong>Note:</strong> Our code cannot compile with javac. That is, it fails compilation if aspects are not woven in (because we have aspects that soften exceptions). <hr /> <strong><em>Update 2/21/2011:</em></strong> There are two equally viable solutions to this (both cases use the <em>aspectj-maven-plugin</em> in conjuction with the <em>maven-compiler-plugin</em>):<br /><br /></p> <ol> <li>Add <code>&lt;failOnError&gt;false&lt;/failOnError&gt;</code> to the compiler plugin (thanks <a href="https://stackoverflow.com/users/70604/pascal-thivent">Pascal Thivent</a>)</li> <li>Add <code>&lt;phase&gt;process-sources&lt;/phase&gt;</code> to the aspectj compiler plugin (thanks <a href="https://stackoverflow.com/users/10433/andrew-swan">Andrew Swan</a>)</li> </ol> <p>More info on these solutions is in the answer section. I believe solution #2 is the better approach.</p> <p><hr /> <br /><br /><br /><br /><br /></p> <h2>Related Questions</h2> <p><strong>Questions (based on failed attempts below):</strong> </p> <p><ol> <li>How do you get maven to run the aspectj:compile goal directly, without ever running compile:compile?</li> <li>How do you ignore the failure of compile:compile?</li> <li>How do you specify a custom compilerId that points to your own ajc compiler (that is make compile:compile use an aspectj compiler other than the plexus one)?*</li> </ol> Thanks for any and all suggestions. These are the things I've tried that have led to my problem/questions: <br><br> <hr> <strong>Attempt 1 (fail):</strong> Specify aspectJ as the compiler for the maven-compiler-plugin:</p> <pre class="lang-xml prettyprint-override"><code>&lt;plugin&gt; &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt; &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt; &lt;version&gt;2.2&lt;/version&gt; &lt;configuration&gt; &lt;source&gt;1.6&lt;/source&gt; &lt;target&gt;1.6&lt;/target&gt; &lt;compilerId&gt;aspectj&lt;/compilerId&gt; &lt;/configuration&gt; &lt;dependencies&gt; &lt;dependency&gt; &lt;groupId&gt;org.codehaus.plexus&lt;/groupId&gt; &lt;artifactId&gt;plexus-compiler-aspectj&lt;/artifactId&gt; &lt;version&gt;1.8&lt;/version&gt; &lt;/dependency&gt; &lt;/dependencies&gt; &lt;/plugin&gt; </code></pre> <p>This fails with the error:</p> <p><code>org.codehaus.plexus.compiler.CompilerException: The source version was not recognized: 1.6</code></p> <p>No matter what version of the plexus compiler I use (1.8, 1.6, 1.3, etc), this doesn't work. I actually read through the source code and found that this compiler does not like source code above Java 1.5.</p> <p><strong>Attempt 2 (fail):</strong> Use the aspectJ-maven-plugin attached to the compile and test-compile goals:</p> <pre class="lang-xml prettyprint-override"><code>&lt;plugin&gt; &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt; &lt;artifactId&gt;aspectj-maven-plugin&lt;/artifactId&gt; &lt;version&gt;1.3&lt;/version&gt; &lt;configuration&gt; &lt;source&gt;1.6&lt;/source&gt; &lt;target&gt;1.6&lt;/target&gt; &lt;/configuration&gt; &lt;executions&gt; &lt;execution&gt; &lt;goals&gt; &lt;goal&gt;compile&lt;/goal&gt; &lt;goal&gt;test-compile&lt;/goal&gt; &lt;/goals&gt; &lt;/execution&gt; &lt;/executions&gt; &lt;/plugin&gt; </code></pre> <p>This fails when running either:</p> <p><code>mvn clean test-compile<br/> mvn clean compile</code></p> <p>because it attempts to execute compile:compile before running aspectj:compile. As noted above, our code doesn't compile with javac--the aspects are required. So mvn would need to skip the compile:compile goal altogether and run only aspectj:compile.</p> <p><strong>Attempt 3 (works but unnacceptable):</strong></p> <p>Use the same configuration above but instead run:</p> <p><code>mvn clean aspectj:compile</code></p> <p>This works, in that it builds successfully but it's unacceptable in that we need to be able to run the compile goal and the test-compile goal directly (m2eclipse auto-build depends on those goals). Moreover, running it this way would require that we spell out every goal we want along the way (for instance, we need resources distributed and tests to be run and test resources deployed, etc)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload