Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » how to configure access rules for ecj when run by maven?
how to configure access rules for ecj when run by maven? [message #1817883] Mon, 02 December 2019 03:53 Go to next message
Eclipse UserFriend
Hi,
For our project we have set the ecj as the compiler to be used by maven.
I'm searching now how to add access rules to eclipse compiler. For example, i want to forbid usage of the old log4j in our code. What i've found so far is that access rules are passed to the eclipse batch compiler via the classpath option [-org/apache/log4j/**]. But when i add this as option in the compiler argument for the maven plugin, it seems to be ignored.

Here is how is setup the ecj in our pom.xml

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<executions>

<execution>
<id>default-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<skipMain>true</skipMain>
</configuration>
</execution>

<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<compilerId>eclipse</compilerId>
<source>1.8</source>
<target>1.8</target>
<compilerArgs>
<arg>-properties</arg>
<arg>${project.basedir}/eclipse.prefs</arg>
<arg>-cp</arg>
<arg>[-org/apache/log4j/**]</arg>
</compilerArgs>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</execution>
</executions>


<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-eclipse</artifactId>
<version>2.8.5</version>
</dependency>

<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>ecj</artifactId>
<version>3.19.0</version>
</dependency>

</dependencies>

</plugin>
Re: how to configure access rules for ecj when run by maven? [message #1817953 is a reply to message #1817883] Tue, 03 December 2019 09:33 Go to previous messageGo to next message
Eclipse UserFriend
I suggest you run maven with -X to see by which exact commandline maven invokes ecj.
I could imagine, that -cp is completely overridden with a corresponding argument synthesized by maven.
Re: how to configure access rules for ecj when run by maven? [message #1818162 is a reply to message #1817953] Mon, 09 December 2019 03:21 Go to previous messageGo to next message
Eclipse UserFriend
Yes, Maven overrides with its own classpath. So the question is how can i pass the access rules to ecj, without using the classpath (or cp) parameter?

Stephan Herrmann wrote on Tue, 03 December 2019 14:33
I suggest you run maven with -X to see by which exact commandline maven invokes ecj.
I could imagine, that -cp is completely overridden with a corresponding argument synthesized by maven.

[Updated on: Mon, 09 December 2019 03:22] by Moderator

Re: how to configure access rules for ecj when run by maven? [message #1818167 is a reply to message #1818162] Mon, 09 December 2019 04:22 Go to previous messageGo to next message
Eclipse UserFriend
Hi

Not sure if this helps, but in my pom.xml I have:

        <plugin>
          <groupId>org.eclipse.tycho</groupId>
          <artifactId>tycho-compiler-plugin</artifactId>
          <version>${tycho-version}</version>
          <configuration><!-- Workaround Bug 526011 -->
            <compilerArgs>
              <arg>-annotationpath</arg>
              <arg>${project.basedir}/../../plugins/org.eclipse.ocl.pivot/annotations</arg>
            </compilerArgs>
          </configuration>


Regards

Ed Willink
Re: how to configure access rules for ecj when run by maven? [message #1818206 is a reply to message #1818167] Tue, 10 December 2019 03:58 Go to previous messageGo to next message
Eclipse UserFriend
Thanks, but i don't think this will do the job. The parameter -annotationpath is for providing the location to external annotations, i don't think it is the same as configuring the access rules. In the batch compiler help the access rules are described as

Quote:
-cp
-classpath <dir 1>;<dir 2>;...;<dir P> This is a list of directories or jar files used to compile the source files. The default value is the value of the property "java.class.path". Entries are separated by the platform path separator.
Each directory or file can specify access rules for types between '[' and ']' (e.g. [-X] to forbid access to type X, [~X] to discourage access to type X, [+p/X:-p/*] to forbid access to all types in package p but allow access to p/X).


But since in my case the classpath is owned by Maven, i was wondering if is there any other way to provide access rules to ecj. For example, thru the prefs file or the environment or something else, that i'm missing.

Ed Willink wrote on Mon, 09 December 2019 09:22
Hi

Not sure if this helps, but in my pom.xml I have:

        <plugin>
          <groupId>org.eclipse.tycho</groupId>
          <artifactId>tycho-compiler-plugin</artifactId>
          <version>${tycho-version}</version>
          <configuration><!-- Workaround Bug 526011 -->
            <compilerArgs>
              <arg>-annotationpath</arg>
              <arg>${project.basedir}/../../plugins/org.eclipse.ocl.pivot/annotations</arg>
            </compilerArgs>
          </configuration>


Regards

Ed Willink

Re: how to configure access rules for ecj when run by maven? [message #1818420 is a reply to message #1818206] Sun, 15 December 2019 07:36 Go to previous message
Eclipse UserFriend
I had to check the sources for a definite answer, but unfortunately, definition of access rules is so tightly coupled to the classpath, that ecj has no provision to merge this information from two separate sources.

From here you could go in several directions, e.g.:

- Request that m2e adds the access rules to the classpath it builds (based on which information)?

- Request that JDT adds an option for merging classpath & rules (how should classpath entries be matched?)

Both request can be made as enhancement requests in bugzilla, but since I don't see a huge community joining this request, you will likely be asked to contribute the implementation yourself.

Stephan
Previous Topic:Access Eclipsse Refactoring API
Next Topic:Developing Processing Sketches in Eclipse
Goto Forum:
  


Current Time: Wed Jul 23 13:41:45 EDT 2025

Powered by FUDForum. Page generated in 0.06280 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top