14

I need to exclude specific source files (NOT just packages) from Javadoc using Maven. The <excludePackageNames> setting will not work for me: it only allows you to exclude certain packages. There's a <sourceFileExcludes> setting that has basically no documentation in the way of usage examples. It just says:

"sourceFileExcludes: exclude filters on the source files. These are ignored if you specify subpackages or subpackage excludes."

So, basically, I need to ignore all Java files that start with Mock, and also all Java files in two packages. Since sourceFileExcludes are ignored if I specify excludePackageNames, I can't combine them. So I tried this:

<sourceFileExcludes>
    <exclude>net/my/packagename/mock</exclude>
    <exclude>net/my/packagename/samples</exclude>
    <exclude>**/Mock*.java</exclude>
</sourceFileExcludes>

But it did not work. None of the intended files were excluded.

Anybody know how to use sourceFileExcludes?

Turnerj
  • 4,258
  • 5
  • 35
  • 52
Nick Williams
  • 2,864
  • 5
  • 29
  • 43
  • [This question](http://stackoverflow.com/q/13465674/1281433) is a bit older, and has a similar problem, but fewer details. – Joshua Taylor Sep 11 '13 at 21:03
  • Did you ever find a solution to this? I'm in a similar situation, and if you found an answer, it'd be great to hear it. – Joshua Taylor Sep 11 '13 at 21:06
  • Unfortunately, I never found a fix for this. I ended up reorganizing my project and put samples in a separate module (which, really, was the "right way"). I then simply didn't generate Javadoc for that module. Sorry. :-/ – Nick Williams Sep 13 '13 at 02:29
  • Aww, that's kind of disappointing. I ended up doing the same thing, too. I may end up trying to find a mailing list for the Javadoc plugin, and asking there. If I do, I'll report back here. – Joshua Taylor Sep 13 '13 at 02:39
  • 2
    Not sure it would work anyway, there is a bug with this tag: http://jira.codehaus.org/browse/MJAVADOC-365?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel – Vince Oct 11 '13 at 08:56
  • seems to work in 2.10.1 – user1050755 Oct 26 '14 at 22:31
  • Is there a way to exclude/ignore methods (not just files/classes)? I tried using `@exclude` and it didn't work – Alexander Mills Feb 18 '19 at 03:05

4 Answers4

7

And what about this?

<sourceFileExcludes>
    <exclude>net/my/packagename/mock/*.java</exclude>
    <exclude>net/my/packagename/samples/*.java</exclude>
    <exclude>**Mock*.java</exclude>
</sourceFileExcludes>
Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
ben75
  • 29,217
  • 10
  • 88
  • 134
  • We're getting closer: ` net/nicholaswilliams/java/mock/** net/nicholaswilliams/java/licensing/mock/** net/nicholaswilliams/java/licensing/samples/** **Mock*.java ` The package excludes are preventing my packages from appearing, so that's good. But there's that one stubborn file (that unfortunately I can't move) that just won't exclude with the fourth exclude. I have even tried a very explicit `net/my/packagename/MockLicenseHelper.java`! – Nick Williams Jan 25 '13 at 20:28
  • did you try to change the order ? i.e. **Mock*.java first – ben75 Jan 25 '13 at 20:58
  • I tried it now. Didn't make a difference with it at the top. I'm beginning to think that this is a bug. – Nick Williams Jan 25 '13 at 21:50
  • One last thing : be sure to clean your javadoc output directory before running + double check for typo errors – ben75 Jan 26 '13 at 10:48
  • Yea, I'm cleaning the entire output directory and then running the entire Maven build again, with no change. I also ran Maven `-debug`, and at Javadoc time it lists all of the exclusion rules and all four of my rules are listed. I copied and pasted the package names and class name, so no typo errors there. It's just like it's not applying the rule. – Nick Williams Jan 26 '13 at 16:37
  • @NickWilliams I've got the same situation, and while `full/package/directory/*.java` successfully hides excludes in that package, including `Foo`, `full/package/directory/Foo.java` _doesn't_. – Joshua Taylor Sep 11 '13 at 21:18
  • Is there a way to exclude/ignore methods (not just files/classes)? I tried using `@exclude` and it didn't work – Alexander Mills Feb 18 '19 at 03:05
7

It might just not be working at the moment. There is bug logged in the plugin issue tracker - MJAVADOC-365

Hardy
  • 18,659
  • 3
  • 49
  • 65
  • Thanks for this. I searched that issue tracker a while ago and couldn't find the bug. I meant to file one, but never got around to it. Now I don't have to! It's a shame that bug hasn't even been responded to in over a year (AND IT HAS A PATCH!). – Nick Williams Oct 08 '14 at 14:15
  • I agree, I am running into the same problem :-( – Hardy Oct 09 '14 at 08:14
  • 2
    I submitted an enhanced patch along with a test case and it has been applied. Looks like it will be in version 2.11 of the plugin. – rec Oct 10 '14 at 05:38
  • 3
    Looks like it was fixed in 2.10.2 – hoshposh Apr 10 '15 at 13:18
  • @hoshposh Yes, it was fixed in 2.10.2. Than you! – CelinHC Nov 01 '16 at 17:26
  • Is there a way to exclude/ignore methods (not just files/classes)? I tried using `@exclude` and it didn't work – Alexander Mills Feb 18 '19 at 03:05
1

You need to specify sourcepath also. Then sourceFileExcludes will work.

<sourceFileExcludes>
  <exclude>CryptoUtils.java</exclude>
</sourceFileExcludes>
<sourcepath>${basedir}/src/main/java/com/sdk/entity;${basedir}/src/main/java/com/sdk/main;${basedir}/src/main/java/com/sdk/util</sourcepath>
Note :

CryptoUtils is inside "/src/main/java/com/sdk/util"

heru762004
  • 46
  • 2
-5
  <sourceFileIncludes>
    <includes>com/cod/user/**</includes>

   </sourceFileIncludes>
  <sourceFileExcludes>
 <exclude>com/cod/user/impl/**</exclude>

includes you want ,exclude else