Here is my setup using offlineimap to sync mail with gmail and dovecot to speak imap with gnus.

1 .gnus file

(setq gnus-select-method
	'(nntp "localhost"))

      (setq gnus-secondary-select-methods
	    '(
	      (nnimap "Mail"
		      (nnimap-stream shell)
		      (nnimap-shell-program
                      "/usr/lib/dovecot/imap -o mail_location=maildir:~/Maildir/:LAYOUT=fs")
		       )
	      (nnfolder "archive"
		(nnfolder-directory   "~/Documents/gnus/Mail/archive")
		(nnfolder-active-file "~/Documents/gnus/Mail/archive/active")
		(nnfolder-get-new-mail nil)
		(nnfolder-inhibit-expiry t))))

  (gnus-registry-initialize)

2 dovecot

Important line in /etc/dovecot/conf.d/10-mail.conf:

# this is the important line
mail_location = maildir:~/Maildir:LAYOUT=fs

3 offlineimap

This is contents of ~/.offlineimaprc

[general]

# defines get_pass()
pythonfile = ~/.offlineimap.py
# List of accounts to be synced, separated by a comma.
accounts = Gmail

[Account Gmail]
# Identifier for the local repository; e.g. the maildir to be synced via IMAP.
localrepository = Gmail-local
# Identifier for the remote repository; i.e. the actual IMAP, usually non-local.
remoterepository = Gmail-remote

[Repository Gmail-local]
type = Maildir
localfolders = ~/Maildir/Gmail

[Repository Gmail-remote]
type = Gmail
remoteuser = me@gmail.com
remotepasseval = get_pass("GMail")
folderfilter = lambda foldername: foldername in ['INBOX', 'Dev', '[Gmail]/Trash']
# Necessary as of OfflineIMAP 6.5.4
sslcacertfile = /etc/ssl/certs/ca-certificates.crt