BALTIMORE (Reuters) - A Maryland judge on Wednesday ordered a Baltimore police officer to testify against other officers charged in the death of detainee Freddie Gray.

Slideshow ( 4 images )

A lawyer for the officer, William Porter, said he would seek an appeals court injunction to block Porter from testifying against Officer Caesar Goodson Jr. and Sergeant Alicia White.

Baltimore City Circuit Court Judge Barry Williams said Porter, whose own trial ended in a hung jury last month, could be compelled to take the stand since state prosecutors had offered him immunity in exchange for testifying.

Williams said during a pre-trial hearing that Porter’s “extremely important testimony is needed in the Goodson and White cases.”

Goodson is the second of six officers scheduled to stand trial for Gray’s death in April and faces the most serious charge, second-degree depraved-heart murder. The trial is set to begin on Monday with jury selection.

The 46-year-old officer, who like Gray is black, was the driver of the van where Gray, who was arrested after fleeing police, sustained the broken neck that killed him.

The majority black city of 620,000 people exploded in arson and rioting after Gray’s funeral. The unrest followed other police killings of black men in cities including New York and Ferguson, Missouri.

Porter’s own trial on involuntary manslaughter and other charges ended in a mistrial last month and a retrial is set for June.

Williams issued his order after denying a defense motion to quash a subpoena forcing Porter to testify. Porter took the stand to say that he would invoke his constitutional right against self-incrimination if called to testify.

Porter’s lawyers said that if he is forced to testify, material could emerge that could be used against him in retrial.

Doug Colbert, a University of Maryland law professor, said of Williams’ decision, “This is a straightforward ruling. The government has the power to compel testimony if they offer immunity.”

Goodson faces up to 30 years in prison if convicted of the murder charge. In Maryland, “depraved-heart” murder is a killing done while acting with extreme disregard for human life.

He also is accused of manslaughter, assault, misconduct in office and reckless endangerment.

Williams also denied a request from Goodson’s lawyers to move the trial out of the city due to the intense publicity surrounding the case.